VBA Macro in Excel to replace drawing format to new company standard---Need help Please
This is what I have so far. Problem comes in when trying to select & delete the format tables on each sheet. Been at this for 2 weeks already and probably have 2 more to go at this pace.
Any help would be greatly appreciated. Help files not very helpful.
Public Sub change_sheet_parameter()
Dim conn As IpfcAsyncConnection
Dim cAC As CCpfcAsyncConnection
Dim CreoSession As IpfcBaseSession
Dim CreoDRW As IpfcModel
Dim sheetData As IpfcSheetData
Dim sheetowner As IpfcSheetOwner
Dim ModelItem As New CMpfcModelItem
Dim sheetInfo As IpfcSheetInfo
Dim paramOwn As IpfcParameterOwner
Dim ipREVISION_LEVEL As IpfcParameter
Dim ipbREVISION_LEVEL As IpfcBaseParameter
Dim pnREVISION_LEVEL As String
Dim REVISION_LEVELnv As IpfcParamValue
Dim ipDRAWING_NUMBER As IpfcParameter
Dim ipbDRAWING_NUMBER As IpfcBaseParameter
Dim pnDRAWING_NUMBER As String
Dim DRAWING_NUMBERnv As IpfcParamValue
Dim ipRMSS_APPROVED As IpfcParameter
Dim ipbRMSS_APPROVED As IpfcBaseParameter
Dim pnRMSS_APPROVED As String
Dim RMSS_APPROVEDnv As IpfcParamValue
Dim ipRMSS_APPROVE_DATE As IpfcParameter
Dim ipbRMSS_APPROVE_DATE As IpfcBaseParameter
Dim pnRMSS_APPROVE_DATE As String
Dim RMSS_APPROVE_DATEnv As IpfcParamValue
Dim ipRMSS_CUSTOMER_REV As IpfcParameter
Dim ipbRMSS_CUSTOMER_REV As IpfcBaseParameter
Dim pnRMSS_CUSTOMER_REV As String
Dim RMSS_CUSTOMER_REVnv As IpfcParamValue
Dim ipRMSS_DRAWN_BY As IpfcParameter
Dim ipbRMSS_DRAWN_BY As IpfcBaseParameter
Dim pnRMSS_DRAWN_BY As String
Dim RMSS_DRAWN_BYnv As IpfcParamValue
Dim ipRMSS_ECO_NUM As IpfcParameter
Dim ipbRMSS_ECO_NUM As IpfcBaseParameter
Dim pnRMSS_ECO_NUM As String
Dim TRMSS_ECO_NUMnv As IpfcParamValue
Dim ipRMSS_ENGR As IpfcParameter
Dim ipbRMSS_ENGR As IpfcBaseParameter
Dim pnRMSS_ENGR As String
Dim RMSS_ENGRnv As IpfcParamValue
Dim ipRMSS_PART_NUM As IpfcParameter
Dim ipbRMSS_PART_NUM As IpfcBaseParameter
Dim pnRMSS_PART_NUM As String
Dim RMSS_PART_NUMnv As IpfcParamValue
Dim ipRMSS_REV As IpfcParameter
Dim ipbRMSS_REV As IpfcBaseParameter
Dim pnRMSS_REV As String
Dim RMSS_REVnv As IpfcParamValue
Dim ipRMSS_REV_DESCR As IpfcParameter
Dim ipbRMSS_REV_DESCR As IpfcBaseParameter
Dim pnRMSS_REV_DESCR As String
Dim TRMSS_REV_DESCRnv As IpfcParamValue
pnDRAWING_NUMBER = "DRAWING_NUMBER"
pnREVISION_LEVEL = "REVISION_LEVEL"
pnRMSS_APPROVED = "RMSS_APPROVED"
pnRMSS_APPROVE_DATE = "RMSS_APPROVE_DATE"
pnRMSS_CUSTOMER_REV = "RMSS_CUSTOMER_REV"
pnRMSS_DRAWN_BY = "RMSS_DRAWN_BY"
pnRMSS_ECO_NUM = "RMSS_ECO_NUM"
pnRMSS_ENGR = "RMSS_ENGR"
pnRMSS_PART_NUM = "RMSS_PART_NUM"
pnRMSS_REV = "RMSS_REV"
pnRMSS_REV_DESCR = "RMSS_REV_DESCR"
Dim workDir As String
Dim sFileName As String
workDir = "C:\Users\jakirsten\Documents\Creo_TEMP"
'MsgBox "Run 01_PURGE_FIRST_Jan.exe First!!!"
Set cAC = New CCpfcAsyncConnection
Set conn = cAC.Connect("", "", ".", 5)
Set CreoSession = conn.session
CreoSession.ChangeDirectory (workDir)
Dim oModelDescriptorCreate As New CCpfcModelDescriptor
Dim oModelDescriptor As IpfcModelDescriptor
sFileName = Dir(CreoSession.GetCurrentDirectory & "\*.drw*")
'sFileName = "4360120-01.drw" 'Name of the drawing
Do Until sFileName = ""
Debug.Print sFileName
Set oModelDescriptor = oModelDescriptorCreate.Create(EpfcMDL_DRAWING, sFileName, Null)
Set CreoDRW = CreoSession.RetrieveModel(oModelDescriptor)
Set sheetowner = CreoDRW
Dim oWindow As pfcls.IpfcWindow
Set oWindow = CreoSession.OpenFile(oModelDescriptor)
oWindow.Activate
'sheetowner.RegenerateSheet (1)
Dim curSheetNum As Long
Dim totalSheets As Long
Dim sheetStep As Long
curSheetNum = sheetowner.CurrentSheetNumber
totalSheets = sheetowner.NumberOfSheets
For sheetStep = curSheetNum To totalSheets
Dim tableObj As IpfcTableOwner
Dim tableToDelete As IpfcTableOwner
Dim table_list As CpfcTables
Dim tableInfo As CpfcTable
Dim CurTABLE As IpfcTable
Dim tblCount, tblStp As Integer
Set tableObj = sheetowner
Set table_list = tableObj.ListTables
tblCount = table_list.Count
For tblStp = 0 To tblCount - 1
Set CurTABLE = table_list.item(tblStp)
' Set tableToDelete = CurTABLE
'tableInfo = CurTABLE
'Debug.Print tableInfo.GetName & " is table name"
If (CurTABLE.CheckIfIsFromFormat(sheetStep) = True And CurTABLE.GetSegmentSheet(0) = sheetStep) Then
'Set tableToDelete = CurTABLE
'tabletodelete.DeleteTable(CurTABLE, False) <-------------------------------------Cannot get this to work
Debug.Print tblStp & " is a format table"
Else
Debug.Print tblStp & " NOT A FORMAT TABLE"
End If
tblStp = tblStp + 1
Next tblStp
tblStp = 0
Next sheetStep
sheetStep = 0
Set paramOwn = CreoDRW
' Set ipTITLE1 = paramOwn.GetParam(pnTITLE1)
' Set ipbTITLE1 = ipTITLE1
Set ipREVISION_LEVEL = paramOwn.GetParam(pnREVISION_LEVEL)
Set ipbREVISION_LEVEL = ipREVISION_LEVEL
Set ipDRAWING_NUMBER = paramOwn.GetParam(pnDRAWING_NUMBER)
Set ipbDRAWING_NUMBER = ipDRAWING_NUMBER
Set ipRMSS_APPROVED = paramOwn.GetParam(pnRMSS_APPROVED)
Set ipbRMSS_APPROVED = ipRMSS_APPROVED
Set ipRMSS_APPROVE_DATE = paramOwn.GetParam(pnRMSS_APPROVE_DATE)
Set ipbRMSS_APPROVE_DATE = ipRMSS_APPROVE_DATE
Set ipRMSS_CUSTOMER_REV = paramOwn.GetParam(pnRMSS_CUSTOMER_REV)
Set ipbRMSS_CUSTOMER_REV = ipRMSS_CUSTOMER_REV
Set ipRMSS_DRAWN_BY = paramOwn.GetParam(pnRMSS_DRAWN_BY)
Set ipbRMSS_DRAWN_BY = ipRMSS_DRAWN_BY
Set ipRMSS_ECO_NUM = paramOwn.GetParam(pnRMSS_ECO_NUM)
Set ipbRMSS_ECO_NUM = ipRMSS_ECO_NUM
Set ipRMSS_ENGR = paramOwn.GetParam(pnRMSS_ENGR)
Set ipbRMSS_ENGR = ipRMSS_ENGR
Set ipRMSS_PART_NUM = paramOwn.GetParam(pnRMSS_PART_NUM)
Set ipbRMSS_PART_NUM = ipRMSS_PART_NUM
Set ipRMSS_ENGR = paramOwn.GetParam(pnRMSS_ENGR)
Set ipbRMSS_ENGR = ipRMSS_ENGR
Set ipRMSS_REV = paramOwn.GetParam(pnRMSS_REV)
Set ipbRMSS_REV = ipRMSS_REV
Set ipRMSS_REV_DESCR = paramOwn.GetParam(pnRMSS_REV_DESCR)
Set ipbRMSS_REV_DESCR = ipRMSS_REV_DESCR
Set DRAWING_NUMBERnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B9").Value)
Set REVISION_LEVELnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B10").Value)
Set RMSS_APPROVEDnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B11").Value)
Set RMSS_APPROVE_DATEnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B12").Value)
Set RMSS_CUSTOMER_REVnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B13").Value)
Set RMSS_DRAWN_BYnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B14").Value)
Set RMSS_ECO_NUMnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B15").Value)
Set RMSS_ENGRnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B16").Value)
Set RMSS_PART_NUMnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B17").Value)
Set RMSS_REVnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B18").Value)
Set RMSS_REV_DESCRnv = ModelItem.CreateStringParamValue(sheets("Parameters").Range("B19").Value)
ipbDRAWING_NUMBER.Value = DRAWING_NUMBERnv
ipbREVISION_LEVEL.Value = REVISION_LEVELnv
ipbRMSS_APPROVED.Value = RMSS_APPROVEDnv
ipbRMSS_APPROVE_DATE.Value = RMSS_APPROVE_DATEnv
ipbRMSS_CUSTOMER_REV.Value = RMSS_CUSTOMER_REVnv
ipbRMSS_DRAWN_BY.Value = RMSS_DRAWN_BYnv
ipbRMSS_ECO_NUM.Value = RMSS_ECO_NUMnv
ipbRMSS_ENGR.Value = RMSS_ENGRnv
ipbRMSS_PART_NUM.Value = RMSS_PART_NUMnv
ipbRMSS_REV.Value = RMSS_REVnv
ipbRMSS_REV_DESCR.Value = RMSS_REV_DESCRnv
oWindow.Close
'CreoSession.EraseUndisplayedModels
sFileName = Dir
Loop
'End the Creo Parametric session when done
''''If Not conn Is Nothing Then
'''' If conn.IsRunning Then
'''' conn.End
'''' End If
''''End If
''''RunError:
'''' If Err.Number <> 0 Then
'''' MsgBox "Process Failed : Unknown error occured." + Chr(13) + _
'''' "Error No: " + CStr(Err.Number) + Chr(13) + _
'''' "Error: " + Err.Description, vbCritical, "Error"
'''' If Not conn Is Nothing Then
'''' If conn.IsRunning Then
'''' conn.End
'''' End If
'''' End If
'''' End If
Set cAC = Nothing
Set conn = Nothing
Set CreoSession = Nothing
Set CreoDRW = Nothing
End Sub

