VBA (API) 在设定的位置将 SOLIDWORKS 工程图保存为 PDF
VBA (API) save SOLIDWORKS drawing as PDF in a set location
我想知道如何修改我的 PDF 保存宏,这样就不会将 PDF 保存在与绘图相同的文件夹中,而是将其保存到在宏中写出的设定位置。
我正在使用的代码是:
Sub Save_PDF()
'Declare variables
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExportPDFData As SldWorks.ExportPdfData
Dim strFilename As String
Dim status As Boolean
Dim errors As Long, warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Export to PDF if it is a drawing
If (swModel.GetType = swDocDRAWING) Then
strFilename = swModel.GetPathName
strFilename = Left(strFilename, Len(strFilename) - 6) & "pdf"
Set swExportPDFData = swApp.GetExportFileData(1)
swModel.Extension.SaveAs strFilename, 0, 0, swExportPDFData, 0, 0
End If
End Sub
有人能帮我解决这个问题吗?
您只需要获取文件名,然后与路径的其余部分连接起来,并删除不需要的行,如下所示:
Option Explicit
Sub Save_PDF()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim strFilename As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel.GetType <> swDocDRAWING Then MsgBox ("Error: Not a drawing"): Exit Sub
strFilename = swModel.GetPathName
strFilename = "G: Design\" & Mid(strFilename, InStrRev(strFilename, "\") + 1, InStrRev(strFilename, ".") - InStrRev(strFilename, "\")) & "pdf"
MsgBox "Save path : " & strFilename
swModel.Extension.SaveAs strFilename, 0, 0, Nothing, 0, 0
End Sub
我想知道如何修改我的 PDF 保存宏,这样就不会将 PDF 保存在与绘图相同的文件夹中,而是将其保存到在宏中写出的设定位置。
我正在使用的代码是:
Sub Save_PDF()
'Declare variables
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExportPDFData As SldWorks.ExportPdfData
Dim strFilename As String
Dim status As Boolean
Dim errors As Long, warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Export to PDF if it is a drawing
If (swModel.GetType = swDocDRAWING) Then
strFilename = swModel.GetPathName
strFilename = Left(strFilename, Len(strFilename) - 6) & "pdf"
Set swExportPDFData = swApp.GetExportFileData(1)
swModel.Extension.SaveAs strFilename, 0, 0, swExportPDFData, 0, 0
End If
End Sub
有人能帮我解决这个问题吗?
您只需要获取文件名,然后与路径的其余部分连接起来,并删除不需要的行,如下所示:
Option Explicit
Sub Save_PDF()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim strFilename As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel.GetType <> swDocDRAWING Then MsgBox ("Error: Not a drawing"): Exit Sub
strFilename = swModel.GetPathName
strFilename = "G: Design\" & Mid(strFilename, InStrRev(strFilename, "\") + 1, InStrRev(strFilename, ".") - InStrRev(strFilename, "\")) & "pdf"
MsgBox "Save path : " & strFilename
swModel.Extension.SaveAs strFilename, 0, 0, Nothing, 0, 0
End Sub