AW: Datei per VBA öffnen / Dateiname ändert sich?
11.03.2018 04:13:05
fcs
Hallo Sergej,
hier mein Vorschlag.
Das Programm mit dem die cfg.Datei geöffnet werden soll musst du ggf. anpassen.
Im Beispiel wird der Windows Editor Notepad.exe verwendet sowie als Variante ein 2. Editor.
Gruß
Franz
'Erstellt unter Windows Vista, Excel 2010
Sub CFG_oeffnen()
Dim strPfad, strDatei, appEdit As Variant
strPfad = "P:\Projekte\2018\München\Service\"
_
If Dir(Left(strPfad, Len(strPfad) - 1), vbDirectory) = "" Then
MsgBox "Verzeichnis " & vbLf & strPfad & vbLf _
& "nicht gefunden!", vbOKOnly, "*Prognose*.cfg Öffnen"
Else
strDatei = Dir(strPfad & "*prognose*.cfg", vbNormal)
If strDatei = "" Then
MsgBox "Im Verzeichnis " & vbLf & strPfad & vbLf _
& "keine Prognose-Datei gefunden!", vbOKOnly, "*Prognose*.cfg Öffnen"
Else
If MsgBox("Datei" & vbLf & strPfad & strDatei & vbLf _
& "öffnen?", vbQuestion + vbOKCancel, "*Prognose*.cfg Öffnen") = vbOK Then
'Datei in Excel als Text-Datei öffnen
' Application.Workbooks.OpenText Filename:=strPfad & strDatei, _
DataType:=xlFixedWidth, local:=True
'Datei in Editor Notepad.exe öffnen
appEdit = VBA.Environ("systemroot") & "\notepad.exe"
If Dir(appEdit) = "" Then
appEdit = VBA.Environ("systemroot") & "\system32\notepad.exe"
If Dir(appEdit) = "" Then
appEdit = ""
End If
End If
If appEdit "" Then
VBA.Shell Pathname:=appEdit & " """ & strPfad & strDatei & """", _
windowstyle:=vbNormalFocus
Else
MsgBox "Programm ""Notepad.exe"" nicht gefunden!"
End If
'Datei in Editor PSPad.exe öffnen - Programm zum Öffen ggf. anpassen
appEdit = VBA.Environ("ProgramFiles") & "\PSPad editor\PSPad.exe"
If Dir(appEdit) "" Then
VBA.Shell Pathname:=appEdit & " """ & strPfad & strDatei & """", _
windowstyle:=vbNormalFocus
Else
MsgBox "Programm ""PSPad.exe"" nicht gefunden!"
End If
End If
End If
End If
End Sub