Hi Adrian.
Glad to assist.
All the best,
Ramesh
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello everyone, I'm here in need of help for a macro in Solidworks that works, but is lacking a crucial check while working.
The macro simply saves the document (drawing) as a PDF. Simple right?
Well, it saves the file in the same location the file is being worked from, locally or in a network and with the same name but the ".pdf" extension.
So far so good.
The problem is access rights. usually you have rights to write the file, but depending on certain conditions you don't.
This is what happens:
Here is the problem:
The macro is only missing a step to check if the file is read only.
If it is, then is should just tell the user the file is read only and finish.
I have tried many ways to do this , but since I'm not trained at all in VB, I simply cannot figure it out...
I have cut and paste several other VB subs but I cannot make it work properly... having errors.
Here is the macro steps that work fine, (I recorded back in 2012) but it lacks the file checking for read only:
____________________________________________________________________________________________________
' ****************************************************************
' Save a Part, Assembly or Drawing as PDF in the same directory.
' By: Adrian Crisci 02/01/2012
' ****************************************************************
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
On Error Resume Next
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtension As String
Dim NewFilePath As String
FilePath = Part.GetPathName
PathSize = Strings.Len(FilePath)
PathNoExtension = Strings.Left(FilePath, PathSize - 6)
NewFilePath = PathNoExtension & "pdf"
Part.SaveAs2 NewFilePath, 0, True, False
End Sub
__________________________________________________________________________________
Can someone add the missing steps to check if the file to be recorded is read only and then quit the macro with a " File is read only" message?
Then the user can go and take control of the file prior to re-writing over it using the macro.
Much appreciated, Thanks!
Adrian
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Hi Adrian.
Glad to assist.
All the best,
Ramesh
Ramesh,
Thank you for the heads up....
Did not know where to start.... I'll post it there...
Regards,
Adrian
Hi Adrian,
Sorry, the Microsoft Community is a forum for home users. Due to the scope of your question, I suggest you ask this question in a VBA forum. 'VBA' Questions - Stack Overflow: https://stackoverflow.com/questions/tagged/vba
Thanks,