wanneer ik op C: schijf de excel file gebruikt net onderstaande vba werkte goed echter wanneer ik de zefde excel file op One Drive open en dan het vba programma uitvoert gaat het fout. wat moet ik aanpassen zodat het ook op de One Drive werkt.
Sub KnopOpslaan()
On Error GoTo ErrHandler:
Dim FolderPath As String
FolderPath = Application.ActiveWorkbook.path
If Right(FolderPath, 1) <> "/" Then
FolderPath = FolderPath & "/"
End If
Dim jaar As Integer
jaar = Sheets("BasisInstellingen").Range("C5").Value
#If Mac Then
FolderPath = CreateFolderinMacOffice2016(NameFolder:="Facturen" & jaar)
#Else
FolderPath = FolderPath & "Facturen" & jaar
If Dir(FolderPath, vbDirectory) = vbNullString Then
MkDir FolderPath
End If
#End If
i = 1
If isEmpty(Range("C18")) Then
pdfname = "Factuur"
Else
pdfname = "Factuur " & Range("C18")
End If
If Dir(FolderPath & "/" & pdfname & ".pdf") <> "" Then
Do While Dir(FolderPath & "/" & pdfname & ".pdf") <> ""
If isEmpty(Range("C18")) Then
pdfname = "Factuur " & " (" & i & ")"
Else
pdfname = "Factuur " & Range("C18") & " (" & i & ")"
End If
i = i + 1
If i = 100 Then
Exit Do
End If
Loop
End If
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(0.3)
.BottomMargin = Application.InchesToPoints(0.1)
.HeaderMargin = Application.InchesToPoints(0.1)
.FooterMargin = Application.InchesToPoints(0.1)
.CenterHorizontally = True
.CenterVertically = False
End With
ActiveSheet.Range("B1:F47").ExportAsFixedFormat Type:=xlTypePDF, Filename:=FolderPath & "/" & pdfname & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
#If Mac Then
If Range("M11").Cells(1, 1).Hyperlinks.Count = 0 Then
Range("M11").Cells(1, 1).Hyperlinks.Add Range("M11").Cells(1, 1), "file:///" & FolderPath, "", "Open PDF folder", "Open PDF Folder"
Range("M11").Font.Size = 14
Range("M11").Font.Bold = True
Range("M11").HorizontalAlignment = xlCenter
Range("M11").VerticalAlignment = xlCenter
End If
#End If
Exit Sub
ErrHandler:
MsgBox "Er is iets mis gegaan"
Resume Next
End Sub
Function CreateFolderinMacOffice2016(NameFolder As String) As String
'Function to create folder if it not exists in the Microsoft Office Folder
'Ron de Bruin : 8-Jan-2016
Dim OfficeFolder As String
Dim PathToFolder As String
Dim TestStr As String
OfficeFolder = MacScript("return POSIX path of (path to desktop folder) as string")
OfficeFolder = Replace(OfficeFolder, "/Desktop", "") & _
"Library/Group Containers/UBF8T346G9.Office/"
PathToFolder = OfficeFolder & NameFolder
On Error Resume Next
TestStr = Dir(PathToFolder, vbDirectory)
On Error GoTo 0
If TestStr = vbNullString Then
MkDir PathToFolder
'You can use this msgbox line for testing if you want
'MsgBox "You find the new folder in this location :" & PathToFolder
End If
CreateFolderinMacOffice2016 = PathToFolder
End Function