VBA export PDF

Sweedler

Board Regular
Joined
Nov 13, 2020
Messages
132
Office Version
  1. 365
Platform
  1. Windows
Hello

I am getting an error on my code, it is showing that something is wrong with the TEXT IN RED. The same code works fine on another document, so I am at a bit of a loss.

I am using the following code to export a PDF copy of my Sheet:

Rich (BB code):
Sub BATfaktura_generator()

Dim bolaget As String
Dim plats As String
Dim datum As String
Dim namn As String

Dim filename As Range
Dim saveLocation As String

bolaget = Sheet6.Range("K1")
plats = Sheet6.Range("K2")
datum = Sheet6.Range("K3")
namn = Sheet6.Range("A2")


    Set filename = Sheet4.Range("A1")
    saveLocation = "C:\Users\marcu\Desktop\EXCELLENT HELP - PC\Customers\Test folder\" & "Namn " & " - " & datum
   
Sheets("INDI SV").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    filename:=saveLocation

End Sub
 
Last edited by a moderator:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I altered some code and now it works

VBA Code:
Sub BATfaktura_generator()

Dim bolaget As String
Dim plats As String
Dim namn As String
Dim year As Integer
Dim month As Integer
Dim day As Integer


Dim filename As Range
Dim saveLocation As String

bolaget = Sheet6.Range("K1")
plats = Sheet6.Range("K2")
namn = Sheet6.Range("A2")
year = Sheet6.Range("K4")
month = Sheet6.Range("K5")
day = Sheet6.Range("K6")



    Set filename = Sheet4.Range("A1")
    saveLocation = "C:\Users\marcu\Desktop\EXCELLENT HELP - PC\Customers\Moll Wenden\Test folder\" & "Namn " & " - " & year & "-" & month & "-" & day
   
Sheets("INDI SV").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    filename:=saveLocation

End Sub
 
Last edited by a moderator:
Upvote 0
Solution

Forum statistics

Threads
1,224,812
Messages
6,181,094
Members
453,021
Latest member
Justyna P

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