Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1840to1844
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Compile error

Compile error
09.08.2021 13:18:50
Dom
Hallo,
ich bekomme folgenden Fehler:
Compile error:
Type-declaration character does not match declared data type
bisher hat es immer geklappt, kann mir bitte jemand sagen woran es liegt ?
Vielen Dank :)
Option Explicit
Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
ByVal DirPath As String) As Long

Public Sub Ordner_erstellen_files_abspeicher_umbennen()
Dim strPath As String
Dim strFile As String
Dim objWorkbook As Workbook
' Öffne das Downloadverzeichnis und wähle File aus, welches in den Ordner verschoben werden soll.
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\1\Downloads\"
.FilterIndex = 2
If .Show Then strFile = .SelectedItems(1)
End With
If strFile  vbNullString Then
strPath = "C:\Users\1\Test " & Format$(Date, "dd_mm_yy") & "\"
Call MakeSureDirectoryPathExists(strPath)
Set objWorkbook = Workbooks.Open(Filename:=strFile)
Call objWorkbook.SaveAs(Filename:=strPath & "Diagram.xlsx", FileFormat:=xlOpenXMLWorkbook)
Set objWorkbook = Nothing
End If
End Sub

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Compile error
09.08.2021 14:21:20
volti
Hallo Dom,
bei mir kommt kein Fehler (Office 365)
Falls es an der API-Funktion liegen sollte, probiere doch mal diese Alternative hier aus.
Code:


Option Explicit Private Declare PtrSafe Function SHCreateDirectoryExW Lib "shell32" ( _ ByVal hwnd As LongPtr, ByVal pszPath As LongPtr, _ ByVal psa As LongPtr) As Long Public Sub Ordner_erstellen_files_abspeicher_umbennen() Dim strPath As String Dim strFile As String Dim objWorkbook As Workbook ' Öffne das Downloadverzeichnis und wähle File aus, welches in den Ordner verschoben ' werden soll. With Application.FileDialog(msoFileDialogOpen) .AllowMultiSelect = False .Title = "Bitte Report auswählen" .InitialFileName = "C:&bsol;Users&bsol;1&bsol;Downloads&bsol;" .FilterIndex = 2 If .Show Then strFile = .SelectedItems(1) End With If strFile <> vbNullString Then strPath = "C:&bsol;Users&bsol;1&bsol;Test " & Format$(Date, "dd_mm_yy") & "&bsol;" Call SHCreateDirectoryExW(0&, StrPtr(strPath), 0&) Set objWorkbook = Workbooks.Open(FileName:=strFile) Call objWorkbook.SaveAs(FileName:=strPath & "Diagram.xlsx", _ FileFormat:=xlOpenXMLWorkbook) Set objWorkbook = Nothing End If End Sub

_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz

Anzeige
AW: Compile error
09.08.2021 16:21:22
Dom
Hallo Karl - Heinz,
eine Umstellung auf 64 bit gab es nicht. Ich hab es mit der Alternative probiert funktioniert Leider auch nicht :(
AW: Compile error
09.08.2021 14:29:10
Daniel
HI
lag es vielleicht an einem Wechsel von Excel32-Bit auf Excel64-bit?
solche "zusatzfunktionen oder API" reagieren da empfindlich drauf und müssen oft dann unterschiedlich programmiert werden.
hatte ich im alten Thread die Alternaivvariante mit MkDir gezeigt? Die sollte Versionsunabhängig laufen.
Gruß Daniel
AW: Compile error
09.08.2021 15:00:24
volti
Hallo Daniel,
hier m.E. nur (wie schon geschehen) der PtrSafe Schlüssel zu beachten. Die Stringvariable und der Rückgabetyp Long bleiben gleich.
BTW: Ich hatte es unter 64 Bit getestet.
Gruß
Karl-Heinz
Anzeige
AW: Compile error
09.08.2021 18:16:30
Luschi
Hallo Excel-Fan's,
- ich arbeite mit einem eingeschränkten Win-User-Konto (habe also keine Admin-Rechte)
- und da werden im Ordner 'C:\Users' (im Explorer sieht man 'C:\Benutzer')
- keine Unterordner erstellt
- weder mit 'MakeSureDirectoryPathExists'
- noch mit 'SHCreateDirectoryExW'
- es kommen aber auch keine Fehler-Aufrufe
- die Behauptung 'bisher hat es immer geklappt' kann einfach so nicht stimmen!
Gruß von Luschi
aus klein-Paris
AW: Compile error
10.08.2021 08:53:39
Dom
Hallo Luschi,
der Fehler trat auf wenn ich das Makro in meiner VBAProjekt (Personal.xlsb) gestartet habe.
In einem neunen Modul in einer Arbeitsmappe klappt es jetzt. Nur ich versteh noch nicht warum :)
Der Code:
Option Explicit
Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
ByVal DirPath As String) As Long

Public Sub Ordner_erstellen_files_abspeicher()
Dim strPath As String
Dim strFile As String
Dim objWorkbook As Workbook
' Öffne das Downloadverzeichnis und wähle File aus, welches in den Ordner verschoben werden soll.
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads\"
.FilterIndex = 2
If .Show Then strFile = .SelectedItems(1)
End With
If strFile  vbNullString Then
strPath = Environ$("USERPROFILE") & "\NoC" & Format$(Date, "dd_mm_yy") & "\"
Call MakeSureDirectoryPathExists(strPath)
Set objWorkbook = Workbooks.Open(Filename:=strFile)
Call objWorkbook.SaveAs(Filename:=strPath & "01ProcessChanges", FileFormat:=xlOpenXMLWorkbook)
Set objWorkbook = Nothing
End If
' Öffne das Downloadverzeichnis und wähle File aus, welches in den Ordner verschoben werden soll.
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads\"
.FilterIndex = 2
If .Show Then strFile = .SelectedItems(1)
End With
If strFile  vbNullString Then
strPath = Environ$("USERPROFILE") & "\NoC" & Format$(Date, "dd_mm_yy") & "\"
Call MakeSureDirectoryPathExists(strPath)
Set objWorkbook = Workbooks.Open(Filename:=strFile)
Call objWorkbook.SaveAs(Filename:=strPath & "02ProcessCancellation", FileFormat:=xlOpenXMLWorkbook)
Set objWorkbook = Nothing
End If
' Öffne das Downloadverzeichnis und wähle File aus, welches in den Ordner verschoben werden soll.
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads\"
.FilterIndex = 2
If .Show Then strFile = .SelectedItems(1)
End With
If strFile  vbNullString Then
strPath = Environ$("USERPROFILE") & "\NoC" & Format$(Date, "dd_mm_yy") & "\"
Call MakeSureDirectoryPathExists(strPath)
Set objWorkbook = Workbooks.Open(Filename:=strFile)
Call objWorkbook.SaveAs(Filename:=strPath & "03DocumentChanges", FileFormat:=xlOpenXMLWorkbook)
Set objWorkbook = Nothing
End If
' Öffne das Downloadverzeichnis und wähle File aus, welches in den Ordner verschoben werden soll.
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads\"
.FilterIndex = 2
If .Show Then strFile = .SelectedItems(1)
End With
If strFile  vbNullString Then
strPath = Environ$("USERPROFILE") & "\NoC" & Format$(Date, "dd_mm_yy") & "\"
Call MakeSureDirectoryPathExists(strPath)
Set objWorkbook = Workbooks.Open(Filename:=strFile)
Call objWorkbook.SaveAs(Filename:=strPath & "04DocumentCancelled", FileFormat:=xlOpenXMLWorkbook)
Set objWorkbook = Nothing
End If
End Sub

Anzeige
AW: Compile error
09.08.2021 16:49:55
Dom
Hallo Daniel,
das mit dem MkDir klappt soweit nur wie kann ich dem Ordner das heutige Datum mitgeben und das die Files die ich ausgewählt habe in dem Ordner abgespeichert werden.
Vielen Dank :)

Sub Abspeichern()
Dim pfad As String
Dim strdatei As String
pfad = "C:\Users\dora101\NoC"  ' Ordner mit heutigem Datum erstellen
MkDir pfad
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads"
.Filters.Add "Arbeitsmappen", "*.xls*", 1
If .Show = -1 Then
strdatei = .SelectedItems(1)
End If
End With
If strdatei  "" Then
Workbooks.Open strdatei
End If
ActiveWorkbook.SaveAs ("C:\Users\dora101\NoC\Report1") ' in den Ordner mit dem heutigem Datum abspeichern
ActiveWorkbook.Close
Dim strdatei12 As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads"
.Filters.Add "Arbeitsmappen", "*.xls*", 1
If .Show = -1 Then
strdatei = .SelectedItems(1)
End If
End With
If strdatei  "" Then
Workbooks.Open strdatei
End If
ActiveWorkbook.SaveAs ("C:\Users\dora101\NoC\Report2")
ActiveWorkbook.Close
Dim strdatei13 As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads"
.Filters.Add "Arbeitsmappen", "*.xls*", 1
If .Show = -1 Then
strdatei = .SelectedItems(1)
End If
End With
If strdatei  "" Then
Workbooks.Open strdatei
End If
ActiveWorkbook.SaveAs ("C:\Users\dora101\NoC\Report3")
ActiveWorkbook.Close
Dim strdatei14 As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Bitte Report auswählen"
.InitialFileName = "C:\Users\dora101\Downloads"
.Filters.Add "Arbeitsmappen", "*.xls*", 1
If .Show = -1 Then
strdatei = .SelectedItems(1)
End If
End With
If strdatei  "" Then
Workbooks.Open strdatei
End If
ActiveWorkbook.SaveAs ("C:\Users\dora101\NoC\Report4")
ActiveWorkbook.Close
End Sub

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige