I need to save around 300 pdf files but every 20-30 files. I have to press "Cancel" for the file to continue saving or else the macro does not keep running. This image will explain better my situation :
'Saving PDF FILE
Application.DisplayAlerts = False
Workbooks(Nom_Fichier_Model_MMS_ON).ExportAsFixedFormat xlTypePDF, _
Filename:=Path_CRM & site_oper & "_" & "4" & num_Canal_Dist & "_" & anneeFisc & ".pdf"
site_oper = Application.WorksheetFunction.Rept("0", 10 - Len(site_oper)) & site_oper
Workbooks(Nom_Fichier_Model_MMS_ON).ExportAsFixedFormat xlTypePDF, _
Filename:=Path_Sharepoint & site_oper & "_" & num_Client & "_MarginReport_312_" & anneeFisc & ".pdf"
Related
I have this code and I would like to save the file in a certain map on my pc.
How could I add a custom path, so I could change it in the future when needed?
As of now it just saves on my desktop.
Code:
ThisWorkbook.SaveAs ThisWorkbook.Path & "\" & Format(Now, "yyyymmdd") & " Testing"
This is the way:-
ThisWorkbook.SaveAs "C:\Users" & Format(Now, "yyyymmdd") & " Testing.xlsx"
You can replace "C:\Users" with any path. But please don't forget to add the file extension at the end.
Solution:
Testing = "C:\Testing\" & Format(Now(), "yyyymmdd") & " Testing " & ".xlsx"
MsgBox "File saved in: C:\Testing\" & vbNewLine & "Your_Second_Text"
ActiveWorkbook.SaveAs Filename:=Testing, FileFormat:=xlOpenXMLWorkbook
I have a code that saves a PDF in the same folder as my workbook. I have a sub folder called PDF Files within the folder and I would like to save there. I can't seem to get it to work. Any help would be appreciated. Below is the code I have so far.
FileName = ThisWorkbook.Path & "\" & .Range("F" & CustRow).Value & "_" & _
.Range("K" & CustRow).Value & ".pdf"
I'm attempting to have my workbook save as a macro-enabled workbook upon execution of my macro. When the macro is initiated, a userform will populate where the user can select a FiscalYear, FormYear, and a FormMonth. The reason for separate years is because FiscalYear will begin in Oct. Oct will be year 18, however it will begin FY19.
I am attempting to insert the value of the FiscalYear into my SaveAs function. The filepath stops after I use FiscalYear and it places the remaining string from the path in front of the DocName I am wanting the workbook to saveas:
Path "J:\x\y\z\FY" & FiscalYear & "\Templates FY" & FiscalYear
DocName:"G22 Dashboard & " " & FormMonth & " " & "FY" & FiscalYear
The document will save in location "FY & FiscalYear &" as "Templates FY18G22 Dashboard & " " FormMonth & " " & "FY" & FiscalYear
Any advice to show me what I am doing incorrectly in this situation?
Probably a rookie mistake, but any help would be greatly appreciated, thanks!
I have attempted different syntax strategies (use of "" locations, & additions/removals).
Sub Save_Report_As()
'Disabling Display Alerts
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Path = "J:\x\y\z\FY" & FiscalYear & "\Templates FY" & FiscalYear
DocName = "G22 Dashboard" & " " & FormMonth & " " & "FY" & FiscalYear
ActiveWorkbook.SaveAs filename:=Path & DocName, FileFormat:=52
'Enabling Display Alerts
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Will post my comment as an answer so this will stop showing up on the "unanswered" list:
path & "\" & docname & ".xlsx" would be more appropriate... you left out the "\" between the path\docname plus the extension (#RyanWildry caught the extension, too)
I think now I tried nearly everything to save a pdf file with Excel vba.
This is my actual code:
Dim pdfFile As String
If excel2016 Then
pdfFile = Application.DefaultFilePath & "/Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
Else
pdfFile = ActiveWorkbook.Path & Application.PathSeparator & "Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
End If
wsOutputOne.ExportAsFixedFormat Type:=xlTypePDF, fileName:=pdfFile
I know that Excel 2016 is creating a "container" and saving the files under ~/Library/Containers/com.microsoft.Excel/Data/Documents/ but why does that code not work with Excel 365?
Or what has a friend with Excel 365 to do to save this generated pdf file?
Because the call of Application.DefaultFilePath returns nothing on his machine...
Can somebody help me?
Please try the following code:
Dim pdfFile As String
If excel2016 Then
pdfFile = Application.DefaultFilePath & "/Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
Else
pdfFile = Application.ActiveWorkbook.Path & Application.PathSeparator & "Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
End If
wsOutputOne.ExportAsFixedFormat Type:=xlTypePDF, fileName:=pdfFile
I have created an application using excel macro, where the user feeds certain values and saves it to several directory path with a button click macro.
When I select a region from drop down, it should save the file to designated region folder. Say for eg, when NY is selected, the file will be saved to shared drive and 2016 - NY folder. But now, deciding the future of the application, I am thinking of having "year" as a separate field in the worksheet, which retrieves the year value from the user. How do I achieve this without the necessity to change the code every year. The process will be continuing for 'n' number of years from now. Thanks in Advance !
FileName1 = Range("D3").Value
filenameOfNewBook = FileName1
If location = "Illinois" Then
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\Illinois\" & FileName1 & "-" & "checklist" & ".xlsm"
ElseIf location = "LA" Then
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\LA\" & FileName1 & "-" & "checklist" & ".xlsm"
ElseIf location = "NY" Then
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\NY\" & FileName1 & "-" & "checklist" & ".xlsm"
Else
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\Atlanta\" & FileName1 & "-" & "checklist" & ".xlsm"
End If
MsgBox "File Saved successfully!", , "Save"
ActiveWorkbook.save
Application.DisplayAlerts = True
From my experience for office tasks purpose, it's better not to refer to current year, but year set by user, so for example in January 2017 user can still perform actions on files related to 2016. You can get rid of the following:
If location = "Illinois" Then
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\Illinois\" & FileName1 & "-" & "checklist" & ".xlsm"
ElseIf location = "LA" Then
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\LA\" & FileName1 & "-" & "checklist" & ".xlsm"
ElseIf location = "NY" Then
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\NY\" & FileName1 & "-" & "checklist" & ".xlsm"
Else
ActiveWorkbook.SaveAs FileName:="W:\Audits\2016\Atlanta\" & FileName1 & "-" & "checklist" & ".xlsm"
End If
And instead use:
Dim myYear as String, locations() as String, locationForPath as String
Dim locCounter as Long
myYear = ThisWorkbook.Worksheets("Sheet1").Range("a2").value2 'the cell with year value, for example 2016
locations = Split("Illinois,LA,NY",",")
For locCounter = LBound(locations) to UBound(locations)
If location = locations(locCounter) Then locationForPath = location: Exit For
Next locCounter
If locationForPath = vbNullString Then locationForPath = "Atlanta"
ActiveWorkbook.SaveAs FileName:="W:\Audits\" & myYear & "\" & locationForPath & "\" & FileName1 & "-" & "checklist" & ".xlsm"