-
11-01-2012, 09:32 AM
#1
Forum Contributor
excel run-time error -2147024773 (8007007b)
Hi Guys,
I’ve got a vba code to save my current sheet as a pdf. All was working well untill i changed the formula in the cell from which the filename is pulled. Now whenever I run the code I get a «excel run-time error -2147024773 (8007007b). Document cannot be saved.». I’ve provided all the vba and formulas below. Any help would be greatly appreciated. Thanks very much
VBA code:
J9 formula previously (worked) =CONCATENATE(«P:Air Import Quotes»,P6,» «,P3,» «,TEXT(P7,»dd-mm-yy»))
J9 formula now (doesn’t work) =CONCATENATE(«P:Air Import Quotes»,P6,» «,P3,» «,TEXT(P7,»dd-mm-yy»),» «,TEXT(P8,»h:mm»))
-
11-01-2012, 09:35 AM
#2
Re: excel run-time error -2147024773 (8007007b)
Hi,
Filenames can’t have a : in them, so the h:mm time format is causing the error. You’ll need to change the : to something else or leave it out entirely.
-
11-01-2012, 09:39 AM
#3
Forum Contributor
Re: excel run-time error -2147024773 (8007007b)
Thanks Colin,
Knew it would be something simple/silly.
Cheers.
-
12-21-2017, 12:59 PM
#4
Registered User
Re: excel run-time error -2147024773 (8007007b)
Good day I’m having the same troubles, I understand that the format date can’t be used with range and VBA, but there is other way to use the content of the cell in that format?
I’m using this code…
Sub Boton1_Haga_click_en()
nombreLibro = Range(«H4»)
Ruta = «D:UsersMXQUEJENDesktop»ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
Ruta & nombreLibro & «.pdf», Quality:=xlQualityStandar, IncludeDocProperties:= _
True, IgnorePrintAreas:=False, OpenAfterPublish:=TrueEnd Sub
I want to save a PDF document with the name of the cell in this case H4 with a format in a custom format mdyyhmms… but H4 have a copy of H3 that have the formula =NOW(). And I want the name of the PDF file is the date in date format.
-
12-21-2017, 01:00 PM
#5
Re: excel run-time error -2147024773 (8007007b)
Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member — start your own thread.
If you feel an existing thread is particularly relevant to your need, provide a
link to the other thread in your new thread.
Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
Ali
Enthusiastic self-taught user of MS Excel who’s always learning!
Don’t forget to say «thank you» to anyone who has offered you help in your thread. You can reward them by clicking on * Add Reputation below theur user name on the left, if you wish.Forum Rules (updated September 2018): please read them here.
How to use the Power Query code you’ve been given: help here. More about the Power suite here.
-
12-21-2017, 01:03 PM
#6
Registered User
Re: excel run-time error -2147024773 (8007007b)
Sorry.. I’ll create a new one.
Thanks
-
#1
Hello,
I get above mentioned error code when I try to run the following macro:
Rich (BB code):
Sub PrintAndSavePdf()
Dim strFileName As String
Dim strPath As String
Dim ws As Worksheet
Dim strPathSplit As Variant
Dim myTempPath As String
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Master" Then
strFileName = ws.Range("I2") & ".pdf"
strPath = ws.Range("I1")
myTempPath = ""
If Dir(strPath, vbDirectory) = "" Then
strPathSplit = Split(strPath, "\")
If UBound(strPathSplit) > 0 Then
myTempPath = "\"
strPathSplit = Split(strPathSplit(1), "")
End If
myTempPath = myTempPath & strPathSplit(0) & ""
For i = 1 To UBound(strPathSplit)
myTempPath = myTempPath & strPathSplit(i) & ""
If Dir(myTempPath, vbDirectory) = "" Then
MkDir (myTempPath)
End If
Next i
End If
ws.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strPath & strFileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next ws
End Sub
Someone gave me this code, but it does not work.
It is an excelmap containing app 70 different worksheets.
On each worksheet there is in cell I1 the path to a server address (IP/path) and in cell I2 the file name, which contains «year name.02.01 — name»
Each sheet has the be stored as pdf under the mentioned path (I1) with the mentioned name (I2)
If the path does not exist the macro should create this path and store the file as descibed.
The red marked section turns to yellow when I open the debug mode.
Can anyone pls help?
Last edited by a moderator: Aug 5, 2021
Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
-
#2
What are the values of strPath and strFileName when this error occurs?
-
#3
Hi Jeff,
thanks for getting back.
Examples are:
for path: \192.168.50.3DoerteProductsApple
for file name: =YEAR(TODAY()) & » » & (F57) & » — ORGANIC CERTIFIED » & (A2)
(The file name in this case is 2021 OBF-CT-APPLE.JC.02.01. — ORGANIC CERTIFIED AND BABY FOOD APPROVED CONCENTRATED APPLE JUICE)
On every sheet is a different path and a different file name.
I dont know, where exactly the error occurs — the only message I get when I click the macro is the failure number of the runtime error.
Thank you!
-
#4
Does anybody has a hint, what might be wrong? Your help is highly appreciated — many thanks in advance!
-
#5
What happens if you manually try to save as pdf and put the file path in your save as box ?
\192.168.50.3DoerteProductsApple
I have had permissions issues using an IP address before which didn’t seem to happen if I used a drive mapping.
-
#6
Hi Alex,
if I save manually in the mentioned directory it is working out.
I’ve also tried to change the path to the drive letter, but it results in the same runtime error.
-
#7
The folders aren’t by any chance on Onedrive or Sharepoint are they ?
-
#8
If not can you try
1) a shorter file name
2) saving it to your c drive.
For 2 make sure the folder exists, the mkdir is only geared for a \ file path.
Also do you know how to set a breakpoint and how to use the immediate window ?
I am in a different timezone (Australia)
-
#9
Hi Alex,
the storage is done on a local server — no share point, one drive or dropbox.
I have shortened the file names — now it lookes like 2021 OBF-CT-APPLE.JC.02.01 — the folder now is created on my local C drive — still not working and the same error.
But the macro should also create a folder, if it does not exist.
Do you have any idea?
Unfortunately I do not know anything about breakpoints or immediate windows.
Regards to Australia and thanks for your effort!
-
#10
1) have you proved that the create a folder part works ?
It is specific to using a network path that needs the \ so I haven’t tested it.
2) Before the line
ws.ExportAsFixedFormat Type:=xlTypePDF,
can you add this line.
VBA Code:
debug.print strPath & strFileName
It should print to the immediate window in the VBA screen.
If you can’t see it press Ctrl+G when you are in the VBA window.
Copy paste the text it outputs in a reply here.
Last edited: Aug 5, 2021
Zeca
As Don said, we can’t see coloured text in questions and you should put code within tags created by the CODE button (as I do below).
I can get your error to occur by using the modified code below and putting any of the characters not allowed in path/ filenames (< > : » / | ? *) in A13 or G13 (or in I7, any except /) — this creates an illegal path and causes the error. (I used «<» in cell G13).
Please check if that is the problem in your file (and if not, read more in the Microsoft guidance here Naming Files, Paths, and Namespaces)
I got your code to work by making the changes below (in bold) so it saves the pdf to the same folder as the Excel file:
Private Sub cmdSavePDS_Click()
Dim ws1 As Worksheet
Dim docName As String
Dim Path As String
ThisWorkbook.Save
Set ws1 = Worksheets("Invoice")
' commented out (since repeated below and Path is not yet defined so "")
'docName = Path & VBA.Format(ws1.Range("I7"), "YYYY-MM-DD") _
& " " & ws1.Range("A13") & " " & ws1.Range("G13") & ".pdf"
Application.DisplayAlerts = False
'Picked local path, same as this file
Path = ThisWorkbook.Path & ""
'Path = "C:UserscarloOneDriveAnitaAnita Invoices"
docName = Path & VBA.Format(ws1.Range("I7"), "YYYY-MM-DD") _
& " " & ws1.Range("A13") & " " & ws1.Range("G13") & ".pdf"
MsgBox "The invoice has been SAVED in .pdf"
ws1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=docName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
' optional addition (for good practice)
Application.DisplayAlerts = True
End Sub
Suggest you use SelectAll to copy that and paste it into your file and see if it works. If so, the problem may be with your path string (commented out above).
Hope this fixes your problem. If so, please remember to mark this Answer as Selected.
Forum Rules |
|