hexagon logo

Downloading the Assignment and saving the values in excel

I have a problem with the code, saving to excel works, but getting the value from assignment V1 causes an error


Sub Main()

Dim objExcel As Object
Dim objWorkbook As Object
Dim objWorksheet As Object

'Nazwa pliku Excel
Dim excelFileName As String
excelFileName = "Excel.xlsx"

'Ścieżka Do pliku Excel
Dim excelFilePath As String
excelFilePath = "T:\Kontrola_jakosci\PC-DMIS\Damian\" & excelFileName

'Jeśli plik Excel nie istnieje, utwórz nowy plik
If Dir(excelFilePath) = "" Then
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Add
    Set objWorksheet = objWorkbook.Sheets(1)

Else
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open(excelFilePath)
    Set objWorksheet = objWorkbook.Sheets(1)
End If

Dim App As Object
Set App = CreateObject ("PCDLRN.Application")
Dim Part As Object
Set Part = App.ActivePartProgram
Dim Var As Object
Set Var = Part.GetVariableValue ("V1")

Dim i As Integer
objWorksheet.Cells(1, 1 ).Value =   "Wymiar x"

i = 1
Do Until objWorksheet.Cells(i,1).Value = empty
i = i +1
Loop

objWorksheet.Cells(i, 1 ).Value  =  Var


objWorkbook.Save
objWorkbook.Close

objExcel.Quit
Set objExcel = Nothing
Set objWorksheet = Nothing
Set objWorkbook = Nothing
End Sub​


Parents
  • What is the error?

    Honestly I am not sure what this code is meant to do -

    i = 1
    Do Until objWorksheet.Cells(i,1).Value = empty
    i = i +1
    Loop​

    The title implies you are writing to Excel from PC-DMIS but first glance at the code snippet implies to me as if it is trying to read from Excel?

    Can you pseudo-code the workflow you are trying to achieve here please? It would save the trouble of trying to reverse engineer the code
Reply
  • What is the error?

    Honestly I am not sure what this code is meant to do -

    i = 1
    Do Until objWorksheet.Cells(i,1).Value = empty
    i = i +1
    Loop​

    The title implies you are writing to Excel from PC-DMIS but first glance at the code snippet implies to me as if it is trying to read from Excel?

    Can you pseudo-code the workflow you are trying to achieve here please? It would save the trouble of trying to reverse engineer the code
Children