Hi, I have written my first VBA macro using the macro recorder. I understand that the recorder adds a lot of unnecessary code but I needed to start learning somewhere!
The macro currently creates an export PDF on my desktop of a specific worksheet, after entering specific values in some cells & applying an advanced filter.
The macro runs through a few different iterations, saving around 30 PDFs on my desktop with different cell values & filters. The PDFs show specific information based on geographical locations.
I've been asked to change it so that rather than creating a PDF it creates a flat excel worksheet with values & formatting rather than data.
So far I have this:
Sub Station_Print()
Dim FilePath As String, dt As String
FilePath = CreateObject("WScript.Shell").specialfolders("Desktop")
dt = Format(CStr(Now), "yyyy-mm-dd")
FIRST ITERATION STARTS HERE
Sheets("As Built Tracker").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = "Station Code"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Station Description"
Range("B3").Select
Range("abt_tracker").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange _
:=Range("af_lis"), Unique:=False
Debug.Print FilePath
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=FilePath & "\File Name 1 - " & dt & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
FIRST ITERATION ENDS HERE
THEN LOADS OF ITERATIONS GO HERE
Sheets("As Built Tracker").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = "Project Wide"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Project Location"
Range("B3").Select
ActiveSheet.Range("abt_tracker").AutoFilter Field:=2
ActiveSheet.Range("abt_tracker").AutoFilter Field:=3
End Sub
I've added my comments in caps for this post (I imagine there's a way of commenting in the code directly but I haven't got that far yet!)
So if there's a bunch of bloated code I'm obviously happy to cut it out but my main query I'm stumped on, is how to save the worksheet on my desktop & paste the values & formatting in to it.
Sorry if I've rambled on too much!
The macro currently creates an export PDF on my desktop of a specific worksheet, after entering specific values in some cells & applying an advanced filter.
The macro runs through a few different iterations, saving around 30 PDFs on my desktop with different cell values & filters. The PDFs show specific information based on geographical locations.
I've been asked to change it so that rather than creating a PDF it creates a flat excel worksheet with values & formatting rather than data.
So far I have this:
Sub Station_Print()
Dim FilePath As String, dt As String
FilePath = CreateObject("WScript.Shell").specialfolders("Desktop")
dt = Format(CStr(Now), "yyyy-mm-dd")
FIRST ITERATION STARTS HERE
Sheets("As Built Tracker").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = "Station Code"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Station Description"
Range("B3").Select
Range("abt_tracker").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange _
:=Range("af_lis"), Unique:=False
Debug.Print FilePath
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=FilePath & "\File Name 1 - " & dt & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
FIRST ITERATION ENDS HERE
THEN LOADS OF ITERATIONS GO HERE
Sheets("As Built Tracker").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = "Project Wide"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Project Location"
Range("B3").Select
ActiveSheet.Range("abt_tracker").AutoFilter Field:=2
ActiveSheet.Range("abt_tracker").AutoFilter Field:=3
End Sub
I've added my comments in caps for this post (I imagine there's a way of commenting in the code directly but I haven't got that far yet!)
So if there's a bunch of bloated code I'm obviously happy to cut it out but my main query I'm stumped on, is how to save the worksheet on my desktop & paste the values & formatting in to it.
Sorry if I've rambled on too much!