Hi all..
I have a workbook with 3 sheets. On sheet 1 I have macro buttons 1 of which "prints/saves as pdf" the current/active sheet. I would like to add a button which "prints/saves as pdf" sheet 2. How is this possible please?
Thanks![]()
Hi all..
I have a workbook with 3 sheets. On sheet 1 I have macro buttons 1 of which "prints/saves as pdf" the current/active sheet. I would like to add a button which "prints/saves as pdf" sheet 2. How is this possible please?
Thanks![]()
Sure, can you post the code you have so far.
Dom
"May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."
Use code tags when posting your VBA code: [code] Your code here [/code]
Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.
Im sorry... Here it is
![]()
Sub Convert2PDF() ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ sFileName, Quality _ :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True End Sub
It would be like this:
![]()
Sub Convert2PDF() Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ sFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, _ IgnorePrintAreas:=False, OpenAfterPublish:=True End Sub
Dom
Fandabby dozy - thank you.
I dont suppose you know how to specify a file name for it to save as? Not a file location just file name? Thanks
Can't test this but maybe:
![]()
Sub Convert2PDF() Dim strFileName As String strFileName = ThisWorkbook.Path & "\MyFile.pdf" Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, _ IgnorePrintAreas:=False, OpenAfterPublish:=True End Sub
Dom
Thanks for trying, unfortunatly it still saves the pdf as the original workbook name![]()
Odd I thought that would work. I assume you've saved the workbook before running the code?
Dom
Yeah I saved it, even closed it down and then reopend it. The code is as below:
![]()
Sub Convert2PDF() Dim strFileName As String strFileName = ThisWorkbook.Path & "\test1.pdf" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ sFileName, Quality _ :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True End Sub
Nearly, I'd called the variable strFileName:
![]()
Sub Convert2PDF() Dim strFileName As String strFileName = ThisWorkbook.Path & "\test1.pdf" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ strFileName, Quality _ :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True End Sub
Dom
Ah ha!! Cool that works fine... Thanks..
I notice you can name the pdf based on a cell content, is it possible to append a cell field infront of the "\test1.pdf" so it would read "\test1-cellcontent.pdf"?
Thanks
Like this:
![]()
strFileName = ThisWorkbook.Path & "\test1-" & Range("A1").Value & ".pdf"
Dom
Exactly like that only it didnt work, Ive got my str's in place this time
![]()
Sub Convert2PDF() Dim strFileName As String strFileName = ThisWorkbook.Path & "\test1-" & Range("A1").Value & ".pdf" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ strFileName, Quality _ :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True End Sub
It will be picking the cell info up from cell A1 on the active worksheet. Is this how you have it set up?
Dom
Excuse my utter stupidity I accidently labled the cell with nothing in it - doh. Works perfectly thanks![]()
No worries. Please mark the thread Solved if you're happy with the solution.
Dom
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks