Hello all,
I created a macro to publish all drawings related to a model as PDF and came across a recent problem that I do not know how to fix. When someone uses a part from our China engineering library I get a hiccup because the China folders have Chinese characters in the folder name. Here is the error message I'm getting:
Microsoft Visual Basic
Run-time error '52':
Bad file name or number
When I try to debug it takes me to this line:
'check for existing file
If Dir(DrawDocName) <> "" Then
I finally figured out what the problem was but I'm not sure how to fix it. Any ideas?
Also, I see that Acrobat has VBA add-ins; does anyone know how to program, at the end of my macro to publish all drawings as PDF's, open Acrobat and combine all files into a single PDF in the order that they were modified? All I could do at the end of my macro is open Acrobat but not combine.
Thanks,
Solved! Go to Solution.
Solved by AJ1227. Go to Solution.
Hi,
If you search for "Dir Unicode VBA" on the net then you can find articles on this issue saying that Dir does not seem to support Unicode. Instead, you should be able to use FileSystemObject:
http://www.mrexcel.com/forum/excel-questions/635230-visual-basic-applications-dir-funtion.html and http://msdn.microsoft.com/en-us/library/aa242706(v=vs.60).aspx
If Acrobat has VBA, then I would think it also has an ActiveX component (like all the Office applications) that could be used from outside. You could start here to look for information on that: http://www.adobe.com/devnet/acrobat/interapplication_communication.html
Hope this helps.
Cheers,
I've changed the macro to use FSO and it no longer hangs up but it is not finding drawings that exist. I referenced Microsoft Scripting Runtime and have changed the code as follows, but my Chinese characters are still being changed to question marks (?) and I think that's why it can't find related drawings.
For Each DocFile In OpenDoc.AllReferencedDocuments
'Get the current part / assembly's path and file name without extension
Dim FSO As New Scripting.FileSystemObject
Dim CurrDocName As String
CurrDocName = FSO.GetAbsolutePathName(DocFile)
'Create the drawing documents full path and file name with extension
Dim DrawDocName As String
DrawDocName = CurrDocName & ".dwg"
'check for existing file
If FSO.FileExists(DrawDocName) = True Then
'drawing exists so perform tasks
Do I have something wrong here?
Thanks.
Ahh, it's not picking up drawings because it's locking in the first parts path as the FSO; how do you get that to reset for each part?
Got it working! All I needed to do from the beginning was add Dim FSO As New Scripting.FileSystemObject and replace Dir with FSO.FileExists. Here is the revised code. Thanks for the help!
'Get the current part / assembly's path and file name without extension
Dim FSO As New Scripting.FileSystemObject
Dim CurrDocName As String
CurrDocName = Left(DocFile.FullFileName, Len(DocFile.FullFileName) - 4) 'without extension
'Create the drawing documents full path and file name with extension
Dim DrawDocName As String
DrawDocName = CurrDocName & ".dwg"
'check for existing file
If FSO.FileExists(DrawDocName) Then
'drawing exists so perform tasks