I have a macro that works perfectly well to copie an excel file from one directory to another and adding in the title of the date. But what I need, is to copy only one sheet of the Excel file, and has it saved as .PDF
Both path (source, new location) should stay the same as the code below.
here is my existing code :
Sub CopierFichier()
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile("\\mtr.intra\367$\profils\R06C286A\_RD\NASC02\Desktop\test\Heures.xls", "V:\DVI\11000_Surveillance\11200_ISP\PCQ\Suivi\FeuilleDeTemps_" & Format(Now(), "DD-MMM-YYYY hh mm AMPM") & ".xls")
End Sub
EDIT:
I just tried something and It worked perfectly. There's one problem, when I run the macro, it takes an eternity to publish the pdf in the directory. Any help is appreciated
this is the code I used :
Sub Macro1()
Sheets("Grille").Activate
ActiveSheet.UsedRange.Select
ThisWorkbook.Sheets("Grille").Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"V:\DVI\11000_Surveillance\11200_ISP\PCQ\Suivi\FeuilleDeTemps_" & Format(Now(), "DD-MMM-YYYY hh mm AMPM") & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
Related
Excel VBA code that worked previously on windows 7 (Excel 2013) no longer works on windows 10 (excel 365).
Now a run time error is generated.
Run-time error '-2147024773 (8007007b)'
Document not saved
The debugger highlights the 4 rows beginning with the first ActiveSheet.ExportAsFixedFormat all the way to False.
Is there a way to alter my code so this runs on windows 10 / excel 365?
Workbooks("Valuation Grail.xlsm").Save
Dim mydir As String
Dim mydrive As String
'Used activeworkbook.path instead of CurDir() because activeworkbook.path does not change for the same saved workbook
mydir = ActiveWorkbook.Path
mydrive = Left(mydir, 1)
'save original wmu as 2 PDFs
Dim month_end As String
Dim generic_vg As String
Dim archived_vg As String
Dim taa_packet As String
'creates saving format for archived pdf
month_end = Format(WorksheetFunction.EoMonth(Now(), -1), "yyyymmdd")
generic_vg = mydrive & ":\01\spec_folder\01 - DATA\Valuations Report\Valuations Report.pdf"
archived_vg = mydrive & ":\01\spec_folder\01 - DATA\Valuations Report\" & month_end & "-Valuations.pdf"
taa_packet = mydrive & ":\01\spec_folder2\#Packet Assembly\TAA\" & "12 - Valuation Grail.pdf"
'Saves the generic and archived version of valuation report to spce_folder data folder
ThisWorkbook.Sheets(Array("Table", "Table_SS")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
generic_vg, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
archived_vg, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ThisWorkbook.Sheets("Summary").Select
'saves the pe tabs to the oshea packet assembly folder
ThisWorkbook.Sheets(Array("PE_Summary", "TAA_SS")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
taa_packet, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ThisWorkbook.Sheets("Summary").Select
ActiveWorkbokk.Path previously returned the full path where the workbook was located including the letter the drive was mapped to (Z, Y, X, etc.). I would then use mydrive to pull only that letter to use in my file path. This method no longer works.
I changed mydrive = "Z" and the code now works.
Ideally I'd like to find a new way to pull that drive letter so members of our team don't have to manually change the mydrive variable each time but this works for now.
I created a workbook in which would be a chart to input data and stored in the same workbook. I managed to create a save path in which the PDF file would be stored but I also need in the same code the coding for saving the sheet in the same workbook as a continuation.
This is what I come up so far for only saving in the PDF format.
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="D:" & Range("H60").Value & Format(Date, "ddmmyyyy")
If somebody could help me would be much appreciated.
Suppose the path is on sheet1
dim path as string 'path variable that stores the path
path="D:" & sheet1.Range("H60").Value & Format(Date, "ddmmyyyy")
'sheets to export
'they must be selected before exporting.
'ThisWorkbook.Sheets(Array("Sheet1", "Sheet2",...)).Select
ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= path, _
Quality:= xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
I hope it helps you
I am looking at creating a PDF from an excel document. I only need part of the worksheet to become part of the PDF. The naming convention of the PDF needs to be dynamic as it is a quotation document.
I have tried the below code already. This is so we can attach the document to an email or build the code to deliver the email to a customer but currently it is failing to run.
```Sub SetEmailToPDF()
ChDir "S:\PDF Quotes"
Worksheets("Email").Range("A1:F70").ExpportAsFixedFormat Type:=xlTypePDF, Filename:= _
"S:\PDF Quotes-" & Format(Now, "DDMMYY") & Worksheets("Email").Range("c12") & ".pdf", OpenAfterPublish:=True
End Sub```
What i expect this to do is produce is a PDF with the file name of 120419Companyname.pdf and this should be saved in s:\PDF Quotes
I have also tried to simplfy to the below code and still get the 438 run time error:
Sub SetEmailToPDF()
ChDir "S:\PDF Quotes"
Worksheets("Email").Range("A1:F70").ExpportAsFixedFormat Type:=xlTypePDF, Filename:= _
"S:\PDF Quotes\test.pdf", OpenAfterPublish:=True
End Sub
I read through a few of the existing VBA questions with this error but I find that the error message is general and there are many, many ways to get it.
My VBA code is below and I am trying to find out why all of a sudden it is not working when it used to. The lines which Excel highlights are between the 2 * which I do not actually have in the code :)
Sub publishPDF()
'
' PublishToPDF Macro
' Macro recorded 01/07/2016 by Pczarnota
' Export to PDF
SaveFolder = "S:\DataOps\InvValidatedFeed\"
DocName = Range("D1").Value
*ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SaveFolder & DocName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False*
MsgBox ("Another one down!")
End Sub
This must have something to do with the filename in D1, the reliance on the ActiveSheet property to define the parent worksheet of D1 or an illegal filename.
Sub publishPDF()
' PublishToPDF Macro
' Macro recorded 01/07/2016 by Pczarnota
' Export to PDF
Dim saveFolder As String, docName As String
saveFolder = "S:\DataOps\InvValidatedFeed\" '<~~ access to the share or network drive?
docName = Worksheets("Sheet1").Range("D1").Value '<~~define the worksheet holding the filename!
If CBool(InStr(1, docName, Chr(46))) Then 'check for a period (full stop)
'remove it; the save type will add the appropriate one
docName = Left(docName, InStr(1, docName, Chr(46)) - 1)
End If
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveFolder & docName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox ("Another one down!")
End Sub
This works for me but I did not duplicate the network share and used abc.xls in Sheet1!D1.
I am creating a template in excel 2010 and I want to make a macro that will save the current document to a folder with the name of a specific cell.
How would I do this?
Say cell D8 in Sheet4 contains:
C:\TestFolder
The try something like:
Sub SaveMe()
s1 = Sheets("Sheet4").Range("D8").Value
ActiveWorkbook.SaveAs s1 & "\" & ActiveWorkbook.Name
End Sub
EDIT#1:
Based on your comments the modified code should be:
Sub SaveMe()
s1 = Sheets("Sheet4").Range("D8").Value
patth = "P:\2013\processed\" & s1 & "\" & ActiveWorkbook.Name
ActiveWorkbook.SaveAs patth
End Sub
Just go to the developer tab and record a macro. Then do a save as to whatever location you want... Then stop recording the macro and view the code. should look like this.
x = the cell you want
ChDir "path"
ActiveWorkbook.SaveAs Filename:= _
"path" & x ".xls", _
FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False