I modified the variable in the SWmoddoc.SaveAs(PathFileNamePDF), I had put the full address with the file, it didn't work I just put the name of the pdf file and it creates it for me in the same folder as the slddrw, and something else if the folder in which I want to save the pdf already exists, This bug, can someone help me understand here is the text of my macro.
sans_titre.png
Hello
I think the error comes from the "PathPDFfileName" variable in this command:
nErrors = SWmoddoc.SaveAs(FileNamePathPDF)
When you save with the "SaveAs" command, you have to put the full name of the file as an argument, WITH the extension (.pdf in your case).
Kind regards.
Franck.
I saw this after Lucas, I modified it, but it still doesn't work.
Fgirard , I also saw this, I modified it but still doesn't work entirely.
pl
July 15, 2014, 12:22pm
13
For the breakpoints, look at the link I put above:
http://www.tomshardware.fr/forum/id-1348092/tutoriel-excel-macro-vba-debogage.html
This explains several ways to debug code, including breakpoints.
1 Like
pl
July 15, 2014, 12:26pm
14
If it still doesn't work, add spies as shown here:
http://www.tomshardware.fr/forum/id-1348092/tutoriel-excel-macro-vba-debogage.html
And what are the values of the variables:
NameFilePDF
PathNameFilePDF
Where does your macro end?
1 Like
re
To help test a macro > in the equation editor, click on "View", on "Local Variable Window", > see attachment
editeur_de_macro_fenetre_variables_locales.png
2 Likes
Our posts intersect, sorry.
It's weird that "SaveAs" doesn't work properly with the full file name (path+name+extension).
Same for the bug with the folder that already exists.
Try with the "SaveAs" command for ModelDocExtension. This is the one I use in my macros.
Here's how to report:
Dim SWmodext as As SldWorks.ModelDocExtension
Dim swExportPDFData As SldWorks.ExportPdfData
Dim Errors As Long Dim Warnings As Long
and how to affect:
Set SWmodext = SWmoddoc.Extension
then:
nErrors = SWmodext.SaveAs(FileNamePathPDF, 0, 0, swExportPDFData, Errors, Warnings)
For folder management, I use the FileSystemObject:
Dim oFSO As Scripting.FileSystemObject Dim oFld As Folder
Set oFSO = New Scripting.FileSystemObject
If oFSO.FolderExists(FileNamePathPDF) = False Then Set oFld = oFSO.CreateFolder(FileNamePathPDF) End If
2 Likes
Thank you caronmaxime , very useful this window!
So with your window, my variables have the value I want to give them, but it doesn't work the way I want it to.
he will create the 2014 file for me, on the other hand if the file already exists it stops at the Mkdir line, (1st point that I don't understand)
and he creates the pdf file for me, but on the other hand in the same folder as the active file when he should put it in the 2014 folder (2nd point that I don't understand)
HELP!!
1 Like
pl
July 15, 2014, 12:54pm
18
Wouldn't the error come from the fact that you test a folder and create another folder?
If Dir$(FileNamePathPDF) = "" Then MkDir FileNamePDF
End if
PathFileNamePDF or should be used here 2 times, right? Once for the Dir$ test and once for the MkDir?
3 Likes
re re
Mathieu, in my opinion your [ MkDir FileNamePDF] should be replaced by [MkDir FileNamePathPDF]
In your macro editor, you can double-click on the MkDir keyword to select it and press F1. Help will allow you to understand.
re re re
take stock taking into account the excellent recommendations of Fgirard and maybe take a look at the question "my PDF DXF macro what to say? " that I published.
Otherwise this is how I proceed (see attachment) to debug a macro when it creates folders or files
capture_decran_sw_et_editeur_sw_et_explorer_windows.png
I made the changes but it still does the same, and when I restart it here or it bugs!
sans_titre.png
pl
July 15, 2014, 1:47pm
22
Ah I think it's because you don't have the backslash at the end of your path!!
To verify this, add this:
If right(FileNamePathPDF,1) = "\" then
FileNamePathPDF = FileNamePathPDF & "\"
End if
You have to put it before your line:
If Dir$(FileNamePathPDF) = "" Then
1 Like
No lucas, it's the same I didn't do it like you said, I did it like that.
FileNamePathPDF = "C:\ANGER\pdf\" & FileNamePDF & "\"
But that doesn't change anything.
On the other hand, how does it work?
nErrors = SWmoddoc.SaveAs(FileNamePDF) FileNamePDF=045/1-2014-A
What should we have in parentheses?
I don't find it and I don't really understand what's on the internet.
pl
July 15, 2014, 2:00pm
24
As mentioned above, your PDFFileName variable must contain the file extension!
So for you.pdf
And maybe the path too?
Try both.
I don't have the possibility to test it currently.
1 Like
I tried the 2 knowing that the variable "FileNamePDF" has the extension originally, but it remains the same, it saves it in the folder where the file is active.
pl
July 15, 2014, 2:33pm
26
So you didn't try to include the destination path (where you want to save it) in FileNamePDF?
Because a "save as" without the path saves it in the folder where the original part is!
1 Like
pl
July 15, 2014, 2:34pm
27
It will be:
nErrors = SWmoddoc.SaveAs(FileNamePathPDF & FileNamePDF)
By making sure that there is a backslash between the 2 (in the first variable or the second, it doesn't matter).
1 Like
pl
July 15, 2014, 2:36pm
28
And for my message of 15:47, it was about the creation of the folder, not the saving of the PDF:
Lucas P
July 15, 2014 - 03:47 PM
Ah I think it's because you don't have the backslash at the end of your path!!
To verify this, add this:
If right(FileNamePathPDF,1) = "\" then
FileNamePathPDF = FileNamePathPDF & "\"
End if
You have to put it before your line:
If Dir$(FileNamePathPDF) = "" Then
1 Like