PDF Exporting Issue

AP1988

New Member
Joined
Aug 9, 2018
Messages
1
Good morning all,

After hours of grappling, I've got the macro I'm writing to do what I want bar one last bit.

Code:
With ActiveWorksheet          
        ChDir Sheet8.Range("F2").Value
        fname = Sheet8.Range("I2").Value
        ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, quality:=xlQualityStandard, _
            includedocproperties:=True, ignoreprintareas:=False, openafterpublish:=False
            
        ActiveWorkbook.Close SaveChanges:=True
        
    MsgBox "PDF exported to " & Sheet8.Range("F2").Text
           
    End With

I can't see what's wrong with the code, it doesn't throw up any errors or debugging - but when the file saves, it doesn't save as a PDF, it just saves without a filetype.

9jhk46.png


Any clues?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I've done some digging, as a previous project of mine also included saving PDF files.

Code:
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.Send
myURL = WinHttpReq.ResponseBody
If WinHttpReq.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write WinHttpReq.ResponseBody
    oStream.SaveToFile "" & sPath & "\TEMP\" & VR1 & ".pdf", 1
    oStream.Close
End If

I hope this helps you out in any way. I used this to pull files from a server and then save them as PDF without opening them, so no idea if this is applicable to your problem.
 
Last edited:
Upvote 0
What is in Sheet8.Range("I2").Value? If it's the full path and required PDF file name, e.g. "C:\folder\path\example.pdf", then the code should work.

It looks like you can delete the With ActiveSheet and End With lines because no objects within that block start with "." to refer to ActiveSheet.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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