Den kommer med Run-time error '1004': Method'SaveAs' of object'_Workbook' failed.
Den henviser til linien: ActiveWorkbook.SaveAs Filename:=FilOgBib, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Hvis jeg trykker på 'end' så har den oprettet bibliotekerne og filen er der også??
Håber at der er nogen som har nogle forslag til hvad jeg kan gøre.
Sub SaveSheetUdregning()
Rem --- Tjek og opret kunde-mappe
Dim StdMappe As String
StdMappe = "C:\Users\hk\OneDrive\TILBUD\"
Dim KundeMappe As String
KundeMappe = Range("A2") 'Kundenavn
strValKundeMappe = KundeMappe
For i = 1 To Len(strValKundeMappe)
Select Case Asc(Mid(strValKundeMappe, i, 1))
Case 32, 48 To 57, 65 To 90, 97 To 122, 192 To 255
' Leave ordinary characters alone 32=space, 48-57=tal, 65-90=A-Z, 97-122=a-z,
Case Else
Mid(strValKundeMappe, i, 1) = " "
End Select
Next i
If Len(Dir(StdMappe & strValKundeMappe, vbDirectory)) = 0 Then
MkDir StdMappe & strValKundeMappe
End If
Rem --- Tjek og opret sags-mappe
Dim SagsMappe As String
SagsMappe = Range("A3") 'Sag
strValSagsMappe = SagsMappe
For i = 1 To Len(strValSagsMappe)
Select Case Asc(Mid(strValSagsMappe, i, 1))
Case 32, 48 To 57, 65 To 90, 97 To 122, 192 To 255
' Leave ordinary characters alone 32=space, 48-57=tal, 65-90=A-Z, 97-122=a-z,
Case Else
Mid(strValSagsMappe, i, 1) = " "
End Select
Next i
If Len(Dir(StdMappe & strValKundeMappe & "\" & strValSagsMappe, vbDirectory)) = 0 Then
MkDir StdMappe & strValKundeMappe & "\" & strValSagsMappe
End If
Rem --- Gem Tilbud
Dim x As String
x = Range("A1")
Dim FilOgBib As String
FilOgBib = StdMappe & strValKundeMappe & "\" & strValSagsMappe & "\" & x & " - UDREGNING - " & strValSagsMappe & ", " & strValKundeMappe & ".xlsm"
Dim TestStr As String
'Test File Path
On Error Resume Next
TestStr = Dir(FilOgBib)
On Error GoTo 0
'Determine if File exists
If TestStr = "" Then
ActiveWorkbook.SaveAs Filename:=FilOgBib, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
MsgBox ("Fil er gemt")
Else
MsgBox ("Kan ikke gemme: FileExist=True")
End If
End Sub