AW: Speichern unter Zelleninhalt
24.06.2014 17:51:00
ransi
HAllo Tom
Nimm als Ansatz mal sowas:
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Public Sub aufruf()
Const PFAD As String = "C:\Test\"
Dim Dateiname As String
With Sheets("Tabelle1")
Dateiname = .Range("A2").Text & .Range("A3").Text
End With
If Dateiname <> "" Then
If erlaubt(Dateiname) = True Then
On Error Resume Next
ThisWorkbook.SaveAs Filename:=PFAD & Dateiname & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
End If
Else:
MsgBox "A2 & A3 =""""", , "Speichern nicht möglich"
End If
End Sub
Public Function erlaubt(strText As String) As Boolean
'CON , PRN, AUX, CLOCK$, NUL # VERBOTEN #
'COM0 , COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9 # VERBOTEN #
'LPT0, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, und LPT9 # VERBOTEN #
'< > ? " : | \ / # VERBOTEN #
'Leerzeichen oder Punkt # VERBOTEN #
Dim Regex
erlaubt = True
Set Regex = CreateObject("Vbscript.regexp")
With Regex
.Pattern = "^(CON|PRN|AUX|CLOCK$|NUL|COM0|COM1|COM2|COM3|COM4|COM5|COM6|COM7|COM8|COM9|LPT0|LPT1|LPT2|LPT3|LPT4|LPT5|LPT6|LPT7|LPT8| LPT9)\..*$"
If .test(strText) = True Then
erlaubt = False
Exit Function
End If
.Pattern = "(<|>|\?|""|:|\||\\|\/|\*)"
.Global = True
If .test(strText) = True Then
erlaubt = False
Exit Function
End If
.Pattern = "( |\.).*\..*$"
If .test(strText) = True Then
erlaubt = False
Exit Function
End If
End With
End Function
ransi