Save a pdf to the desktop with a filename as a cell reference

B

Beric Dondarrion

I'm currently working on a macro that is on a network (i.e. deals with the
Ne0x issue"), saves a pdf of a certain print area to the desktop, bypasses
the "Save as" box of the non MS pdf writer (Doro PDF Writer), and names the
file based on a cell reference.

Whew!

I've got everything working except the filename = cell reference

Here's what is currently working if I wanted to just pick an arbitrary
filename:

ActiveSheet.ExportAsFixedFormat _
Type:=x1typepdf, _
Filename:="C:\Documents and Settings\all users\Desktop/test.pdf", _
Openafterpublish:=False

I'm aware of the forward slash. For some reason, that's working. Anyway,
this is what I thought would work:

ActiveSheet.ExportAsFixedFormat _
Type:=x1typepdf, _
Filename:="C:\Documents and Settings\all users\Desktop/" _
& Range("A18").Value & ".pdf", _
Openafterpublish:=False

But it's not. I get a run time error and a "File not Saved" notice. Btw,
the line break in the filepath is only in this post because the message box
isn't wide enough.

Any help would be great.
 
P

Per Jessen

Hi


Try to use a variable to build the file name string before the
ExportAsFixedFormat statement.

Dim PDFFileName As String
PDFFileName = _
"C:\Documents and Settings\all users\Desktop/" _
& Range("A18").Value & ".pdf"

ActiveSheet.ExportAsFixedFormat _
Type:=x1typepdf, _
Filename:=PDFFileName, _
Openafterpublish:=False

Hopes this helps.

Regards,
Per
 
B

Beric Dondarrion

I tried that and had the same problem.

The good news is that I solved the problem. There were a few cut/paste
operations earlier in the code that I didn't post. I realized that the cell
I was referencing for the "save as" was on a different sheet and blank. Duh.


However, now I'm running into a trickier problem. This macro works on 3 of
5 computers tested at my company so far. The problem is in the filepath, I'm
betting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top