Andy Zhou wrote:
So my question is that, I'm not sure how to pull values from excel sheet; then search through the folder and replace it with another value from excel cell. Does anyone have an idea?
You will have to add a reference of Microsoft Excel 14.0 Object Library.
And then using CreateObject("Excel.Application") or GetObject(, "Excel.Application") you can access the excel files.
Similarly, to search through folder, you may need to add reference of Microsoft Scripting Runtime
And using CreateObject("Scripting.FileSystemObject") or GetObject(, "Scripting.FileSystemObject").
However, you should use 'PackNGo' instead of FileSystemObject so that you can maintain the references of SolidWorks files.
Instead of using scripting, would this also work? Trying to get if the Value (old name) matches the nValue(new name), and it has the right file extension, it will rename accordingly.
Dim PackAndGoObj As PackAndGo
Set PackAndGoObj = swModelDocExt.GetPackAndGo
Dim result As Boolean
PackAndGoObj.FlattenToSingleFolder = True
PackAndGoObj.IncludeToolboxComponents = True
PackAndGoObj.IncludeDrawings = True
result = PackAndGoObj.GetDocumentNames(VDocs)
Dim xl As Excel.Application
Dim xlsh As Excel.Worksheet
Set xl = GetObject(, "Excel.Application")
Set xlsh = xl.ActiveSheet
Dim row As Integer
row = 1
For i = 0 To UBound(VDocs)
Value = xlsh.Cells(row, 1).Value
nValue = xlsh.Cells(row, 2).Value
If Value = Split(VDocs(i), ".")(0) And Split(VDocs(i), ".")(1) = "sldprt" Then
VDocs(i) = "nValue" & ".sldprt"
ElseIf Value = Split(VDocs(i), ".")(0) And Split(VDocs(i), ".")(1) = "sldasm" Then
VDocs(i) = "nValue" & ".sldasm"
ElseIf Value = Split(VDocs(i), ".")(0) And Split(VDocs(i), ".")(1) = "slddrw" Then
VDocs(i) = "nValue" & ".slddrw"
row = row + 1
result = PackAndGoObj.SetSaveToName(True, SavingPath)
result = PackAndGoObj.SetDocumentSaveToNames(VDocs)
vResult = swModelDocExt.SavePackAndGo(PackAndGoObj)
Thats what i wanted to suggest. This should work.
If you only want to rename files in Excel cells in a certain orders, you can create simple script in Excel without calling SW API
Hi I have a similar requirement.
I have part files in a folder and need to rename it by using excel.
All are individual parts. I just want to rename it with equivalent name in excel.
There are 400 such parts in the folder.
Existing New name 355tg Festo_cylinder_355tg K1225 Mcmaster_washer_K1225 T305f Mcmaster_hinge_T305f
Any macro available?