cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Using excel in journal. 2 files and excel macro object

Creator
Creator

Hi everyone,

 

I would like to use some excel command in my journal. I want to write some NX data to one .xslx file and copy some data produced by NX in the form of a .csv file to the same .xslx file.

 

All the "write NX data to .xlsx file" part is done and works just fine but the other part is problematic.

 

 

 

My approach was to have one excel object with 2 workbooks open and to copy/past from one file to the other.

 

Dim objExcel As Object

objExcel = CreateObject("Excel.Application")

wkb1 = objExcel.WorkBooks.Open(xslxFile)

wkb2 = objExcel.WorkBooks.Open(csvFile)

wkb1.cells(pos1,pos2).value = wkb2.cells(pos3,pos4).value <=== Error

 

but this code give me this error : 

"System.MissingMemberException: the public member 'cells' of type 'workbook' is not found."

 

So if I understand correctly there is no possibility to write in a file using the workbook as the 'cells' objects are not defined for the 'workbook' class?

 

I thought of a way to go around this issue and it would be to use the excel object to open one file, save my usefull data in the form of some NX variable, close the file, open the other file and write in there the data I saved before. I think it would work but it seems a lot clumsy and not efficient at all.

 

I also have another question related to the subject. In my code I use 

 

objExcel.cells.EntireColumn.AutoFit()

 

and it works, so it seems possible to use excel command in NX.

I would like to use the Range() object to select data to copy but I never managed to make it work. Can you help me ?

 

Thanks a lot,

 

Mathieu

2 REPLIES

Re: Using excel in journal. 2 files and excel macro object

Honored Contributor
Honored Contributor

but this code give me this error : 

"System.MissingMemberException: the public member 'cells' of type 'workbook' is not found."

 

So if I understand correctly there is no possibility to write in a file using the workbook as the 'cells' objects are not defined for the 'workbook' class?

 

 

The Excel "workbook" object does NOT have a .cells property. You get the error message because you are trying to access a property that the object does not possess. A "workbook" object contains a collection of "worksheet" objects. The Excel "worksheet" object DOES have a .cells property; try getting a reference to the worksheet(s) of interest. The code you have will probably work if you reference the worksheets instead of the workbooks.

Re: Using excel in journal. 2 files and excel macro object

Creator
Creator

Thanks for the help.

 

I managed to achieve my goal but I had to first open the file, import the data needed in NX, close the file, open the other file and paste the said data.

 

Mathieu