Saving individual tabs as PDF with set naming convention

stroffso

Board Regular
Joined
Jul 12, 2016
Messages
125
Hi All,

I have a workbook which has 16 tabs in it (and potentially more) which are quotes for indivdual clients.

What i want to do is have a macro which saves each tab as a pdf under the naming convention "Quote" Then the tab name, then cell D2, then cell D4. This would need to be saved in a specified folder on my D drive.

I have checked on this forum and found several pieces of code that relate to naming arrays but is there any way where it would just print/pdf all tabs and apply the above without having to name each one?

thanks in advance
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,718
Office Version
2010
Platform
Windows
Code:
Sub stroffso()
  Const sPath       As String = "D:/somePath/Quote"
  Dim wks           As Worksheet

  For Each wks In Worksheets
    With wks
      .ExportAsFixedFormat _
          Type:=xlTypePDF, _
          Filename:=sPath & .Range("D2").Value & Range("D4").Value
    End With
  Next wks
End Sub
 

stroffso

Board Regular
Joined
Jul 12, 2016
Messages
125
Thanks for that. Thr first time I ran this it worked fine however ever since it kee[ps returning a run time error '1004'? I thought it might have been cause I had too many tabs in the doc but tried it with just 5 tabs and it still didnt work? Any ideas?

Code:
Sub stroffso()
  Const sPath       As String = "D:/somePath/Quote"
  Dim wks           As Worksheet

  For Each wks In Worksheets
    With wks
      .ExportAsFixedFormat _
          Type:=xlTypePDF, _
          Filename:=sPath & .Range("D2").Value & Range("D4").Value
    End With
  Next wks
End Sub
 

stroffso

Board Regular
Joined
Jul 12, 2016
Messages
125
Ok so i took the 2nd cekk Rabge Value off and it appeared to work. I think I know what the issue is now, the 2nd cell range was a date and had / / in it so i presume this is where the error has come from. thanks for the solution.
Thanks for that. Thr first time I ran this it worked fine however ever since it kee[ps returning a run time error '1004'? I thought it might have been cause I had too many tabs in the doc but tried it with just 5 tabs and it still didnt work? Any ideas?
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,718
Office Version
2010
Platform
Windows
You're welcome.
 

Forum statistics

Threads
1,082,298
Messages
5,364,377
Members
400,795
Latest member
Vercas

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top