# Runtime error 1004- SaveAsPDF



## Sven001 (Aug 5, 2022)

I tried everthing to fix the rumtime error, can you help.

I keep getting the run time error with the yellow text in the code.

Is it maybe to do with work using the dropbox and the path?

Code below:


Sub SaveAsPDF()

Dim invo As Long
Dim custname As String
Dim custname1 As String

Dim DT_issue As Date
Dim path As String
Dim fname As String
Dim nextrec As Range

invno = Range("B7")
custname = Range("A18")
custname1 = Range("A4")
DT_issue = Range("B8")
path = "C:\Users\SeebergerSve\Dropbox (STRABAG SE)\HH-RL-240 AUSF\HH-RLHX_Schalungsbau\00_Allgemeine Unterlagen Schalungsbau\13_Schalungsbau_INFO\04_Neu Lieferschein_PDF\"

fname = invno & " - " & custname

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, IgnorePrintAreas:=False, Filename:=path & fname & ".pdf"

Set nextrec = Tabelle3.Range("A104876").End(xlUp).Offset(1#)

nectrec = invno
nextrec.Offset(0, 1) = DT_issue
nextrec.Offset(0, 2) = custname1
nextrec.Offset(0, 3) = custname

Tabelle3.Hyperlinks.Add anchor:=nextrec.Offset(0, 4), Address:=path & fname & ".pdf"

End Sub


----------



## Jimmypop (Aug 5, 2022)

One issue I can think of is maybe at your declarations:


```
Dim invo As Long
```

is your declaration... However in the rest of the code you use:

"invno" instead of "invo"

Maybe try changing that first?


----------



## Sven001 (Aug 5, 2022)

Jimmypop said:


> One issue I can think of is maybe at your declarations:
> 
> 
> ```
> ...


HI Jimmypop

thank you

changed it, but still giving the run time error 1004


----------



## Jimmypop (Aug 5, 2022)

What is the entire error message saying?


----------



## Sven001 (Aug 9, 2022)

Translation above:

Runtime error '1004

Microsoft Excel cannot access the file 'C:\Users\SeebergerSve\Desktop\Xcel
Delivery note\157 - 256 \D92E5710' cannot be accessed.This can have several reasons:

- The name of the document or the path does not exist.
- The document is used by another program.
- The name of the workbook to be saved is identical to the name of another document that is read-only.


----------



## Jimmypop (Aug 9, 2022)

The path you gave in original post and the one in photo do not match... So a bit difficult to determine now... Also are you trying to save as a pdf or xlsx...


----------



## Sven001 (Aug 9, 2022)

Sorry.

A bit hectic at work-

I have gone a step back to my Excel file save, as I am also having a problem there with the path 

I also change the path to desktop, as I thought that the dropbox path could be the problem.

My next step to save Copy of invoice as a PDF and send it off in a email.

Should I maybe start over again??


----------



## Jimmypop (Aug 9, 2022)

Mmmm maybe a good idea... Just make sure the file path is 100 percent correct... All slashes... Uppercase and lowercase... Also make sure that there are no special characters in file name... Also make sure there is no other files with the same name...


----------



## Jimmypop (Aug 10, 2022)

Hi Sven

I have tested with part of your code... both saving to excel format and pdf worked fine on my side... I however do not have dropbox so could not test with that... Your problem is definately your path specified....

Have you tried copying the file path directly from the address bar from where you want to save? Or are you trying to retype it manually? Maybe try copying it directly from address bar...


----------



## piyushbund77 (Aug 10, 2022)

I am trying to create a PDF of a worksheet on a test workbook with a few values entered into cells. The code for this seems common. I try to run it and i get this error. I can't figure out what's wrong. Any ideas?

Sub Button1_Click()
Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook
Set ws = Worksheets("Sheet1")

ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:="Desktop\itti.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub


----------



## Sven001 (Aug 5, 2022)

I tried everthing to fix the rumtime error, can you help.

I keep getting the run time error with the yellow text in the code.

Is it maybe to do with work using the dropbox and the path?

Code below:


Sub SaveAsPDF()

Dim invo As Long
Dim custname As String
Dim custname1 As String

Dim DT_issue As Date
Dim path As String
Dim fname As String
Dim nextrec As Range

invno = Range("B7")
custname = Range("A18")
custname1 = Range("A4")
DT_issue = Range("B8")
path = "C:\Users\SeebergerSve\Dropbox (STRABAG SE)\HH-RL-240 AUSF\HH-RLHX_Schalungsbau\00_Allgemeine Unterlagen Schalungsbau\13_Schalungsbau_INFO\04_Neu Lieferschein_PDF\"

fname = invno & " - " & custname

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, IgnorePrintAreas:=False, Filename:=path & fname & ".pdf"

Set nextrec = Tabelle3.Range("A104876").End(xlUp).Offset(1#)

nectrec = invno
nextrec.Offset(0, 1) = DT_issue
nextrec.Offset(0, 2) = custname1
nextrec.Offset(0, 3) = custname

Tabelle3.Hyperlinks.Add anchor:=nextrec.Offset(0, 4), Address:=path & fname & ".pdf"

End Sub


----------



## Jimmypop (Aug 10, 2022)

piyushbund77 said:


> I am trying to create a PDF of a worksheet on a test workbook with a few values entered into cells. The code for this seems common. I try to run it and i get this error. I can't figure out what's wrong. Any ideas?
> 
> Sub Button1_Click()
> Dim wb As Workbook
> ...



Good day and welcome

Not sure if against rules but it is advisable to start your own new thread and not on someone else post...

That being said you need to reference your entire file path... Just replace the path below with the physical path with yours...


```
Sub Button1_Click()
    Dim wb          As Workbook
    Dim ws          As Worksheet
    Set wb = ActiveWorkbook
    Set ws = Worksheets("Sheet1")
    ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\Jimmypop\Desktop\itti.pdf", _
                           Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                           IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
```


----------



## Sven001 (Aug 10, 2022)

Jimmypop said:


> Hi Sven
> 
> I have tested with part of your code... both saving to excel format and pdf worked fine on my side... I however do not have dropbox so could not test with that... Your problem is definately your path specified....
> 
> Have you tried copying the file path directly from the address bar from where you want to save? Or are you trying to retype it manually? Maybe try copying it directly from address bar...



Thank you I will give that a go


----------



## Sven001 (Aug 11, 2022)

Jimmypop said:


> Hi Sven
> 
> I have tested with part of your code... both saving to excel format and pdf worked fine on my side... I however do not have dropbox so could not test with that... Your problem is definately your path specified....
> 
> Have you tried copying the file path directly from the address bar from where you want to save? Or are you trying to retype it manually? Maybe try copying it directly from address bar...


Hi Jimmypop

I tried that, no luck

Its defaintle the path, everythings else seems to running well. Its just not saving the file to Excel Folder, via dropbox


----------



## Jimmypop (Aug 11, 2022)

Sven001 said:


> Hi Jimmypop
> 
> I tried that, no luck
> 
> Its defaintle the path, everythings else seems to running well. Its just not saving the file to Excel Folder, via dropbox



Then maybe someone who has some experience with Dropbox might enlighten us as to a solution?


----------



## Sven001 (Aug 11, 2022)

Jimmypop said:


> Then maybe someone who has some experience with Dropbox might enlighten us as to a solution?


Or just have to manually save the invoice each time 

Going to look this evening more online, will keep you posted


----------



## piyushbund77 (Dec 30, 2022)

I am trying to create a PDF of a worksheet on a test workbook with a few values entered into cells. The code for this seems common. I try to run it and i get this error. I can't figure out what's wrong. Any ideas?

Sub Button1_Click()
Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook
Set ws = Worksheets("Sheet1")

ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:="Desktop\itti.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub

https://www.routerlogin.net/
pikashow


----------

