Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 31st, 2020, 01:17 AM
Authorized User
Points: 400, Level: 6
Points: 400, Level: 6 Points: 400, Level: 6 Points: 400, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2009
Posts: 69
Thanks: 6
Thanked 0 Times in 0 Posts
Default Saving a pdf file

Hi,
I am trying to save an Excel worksheet in pdf format in a specific folder. Below is the code:
Code:
Sub SaveInvoice()
Dim fName As Variant, strPathLocation As String

If Month(Date) > 6 And Month(Date) < 13 Then
    strPathLocation = "D:\Elegance Acctng\Elegance Acctng_Financial Records_" & Format(Date, "yyyy") & "-" _
    & Format(Date, "yy") + 1 & "\Tax Invoices Storage_" & Format(Date, "yyyy") & "-" & Format(Date, "yy") + 1 & "\"

ElseIf Month(Date) > 0 And Month(Date) < 7 Then
    strPathLocation = "D:\Elegance Acctng\Elegance Acctng_Financial Records_" & Format(Date, "yyyy") - 1 & "-" _
    & Format(Date, "yy") & "\Tax Invoices Storage_" & Format(Date, "yyyy") - 1 & "-" & Format(Date, "yy") & "\"
    
End If
    
    fName = Application.InputBox("Type Invoice Number")     'Application.InputBox is a method not a function
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPathLocation & fName
End Sub
In this code the path where the document will be saved is:
D:\Elegance Acctng\Elegance Acctng_Financial Records_2019-20\Tax Invoices Storage_2019-20\, and the code is perfect since it is giving the right path. However, when the code reaches the last line I get this error:

"Run-time error 1004
Document not saved. The document may be open, or an error may have been encountered when saving"

I don't know what the error is and why it is happening since the directory path is correct.

Any help would be appreciated.
Thank you
Khalil
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving a File with vba pooky BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2 0 June 20th, 2012 10:23 PM
Clear the filepath details of File Upload Control after saving a file DineshGirij008 C# 2005 0 March 7th, 2009 03:52 AM
saving a file tinybunny_8 ASP.NET 2.0 Professional 0 February 1st, 2006 05:39 PM
EXCEL question saving a file saving the the first macupryk VS.NET 2002/2003 0 January 6th, 2005 05:33 PM
Help saving a file. mbwegner Beginning VB 6 1 December 20th, 2004 11:26 AM



All times are GMT -4. The time now is 03:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.