Macro Help!

JFORTH97

New Member
Joined
Nov 26, 2020
Messages
10
Office Version
  1. 365
Platform
  1. MacOS
Hi

I'm trying to create a Macro so from my worksheet by pressing a button it will export it as a PDF, but then save it based on 3 cell Values, C4, C6 & C8.

C4 is a name
C6 is a name
C8 is a date

I'm wanting it to save to a specific file location to: C:\Users\Vector\Google Drive\H_O Office\Timesheets for Head Office

Can anyone help me, would be much appreciated!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Create a button on your sheet and assign this macro to it:
VBA Code:
Sub SavePDF()
    ChDir "C:\Users\Vector\Google Drive\H_O Office\Timesheets for Head Office\"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C4") & " " & Range("C6") & " " & Range("C8") _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
End Sub
 
Upvote 0
Create a button on your sheet and assign this macro to it:
VBA Code:
Sub SavePDF()
    ChDir "C:\Users\Vector\Google Drive\H_O Office\Timesheets for Head Office\"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C4") & " " & Range("C6") & " " & Range("C8") _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
End Sub
Thanks for that its saying Run-time error '1004'

Any reason why?
 
Upvote 0
Which line of code is highlighted when you click "Debug"?
 
Upvote 0
How about like
VBA Code:
Sub SavePDF()
   Dim Pth As String
    Pth = "C:\Users\Vector\Google Drive\H_O Office\Timesheets for Head Office\"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=Pth & Range("C4") & " " & Range("C6") & " " & Format(Range("C8"), "dd-mm-yyyy") _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
End Sub
Change the date format to suit.
 
Upvote 0
Which line of code is highlighted when you click "Debug"?
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("C4") & " " & Range("C6") & " " & Range("C8") _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
 
Upvote 0
Have you tried Fluff's suggestion in Post #5? I neglected to take the date format into account.
 
Upvote 0
Is the sheet that you want to save the active sheet when you run the macro?
 
Upvote 0
Yes, here's a picture of the screen
IMG_0054.jpg
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top