Wrox Programmer Forums
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 31st, 2020, 01:17 AM
Authorized User
Join Date: Dec 2009
Posts: 69
Thanks: 6
Thanked 0 Times in 0 Posts
Default Saving a pdf file

I am trying to save an Excel worksheet in pdf format in a specific folder. Below is the 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

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

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