Cancel
Showing results for 
Search instead for 
Did you mean: 

NX Open printing numbers in Excel

Experimenter
Experimenter

Hi guys,

 

I'm trying for a while now to make NX Open print numbers in Excel 2013 (I'm using VB). I've generated an NX user surface with the Block UI Styler and want the numbers I put in there to occur in Excel when pushing a button (button01). I guess it cannot be so hard to realize but I'm getting kind of desperate because it won't work .... I've attached a file showing my probably best try so far Smiley Wink

Excel is opening when pusching button01, but the numbers are only printed in the desired rows after having restarted Excel for several times.

I'm thankful for any help!!

 

Greetings from Germany,

Laura

1 REPLY

Re: NX Open printing numbers in Excel

Phenom
Phenom

Guten Morgen Laura,

 

Where do you specify the target worksheet? Are you assuming that it is the active sheet? It looks like you are pointing to the 'Excel object' to write data to a cell and not a specific worksheet in your selected workbook

 

When used Excel to "print" data (albeit from a csv file creted by NX) I used the following

 

Dim objExcel As Object			'The Excel application
Dim objWBookToUse As Object		'The newly created excel file (workbook)

'create Excel object
objExcel = CreateObject("Excel.Application")
	If objExcel Is Nothing Then
		theNXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Could not start Excel Application - Program exiting")
		Exit Sub
	End If
	
objWBookToUse = objExcel.Workbooks.Open (FileName:=sFileToProcess, ReadOnly:=True)	

'Set the active sheet in the newly created xls file 'The active sheet in the created xls file  = Sheet1
Dim shData As Object = objWBookToUse.ActiveSheet	

Dim DataTargetRg As Object   'Range
	'one way of defining a target "range" for excel
	DataTargetRg = shData.Cells(2, 1)		'.Range("A2")
	
'An example to write value to a cell
	irow=1 : icol = 1
		shData.Cells(irow,icol+1).Value = "A"
		shData.Cells(irow,icol+2).Value = "B"
		shData.Cells(irow,icol+3).Value = "C"	
		
		
'objWBookToUse.Save()	'Need a name 1st!
'objWBookToUse.Close()	'otherwise stay open 
'objExcel.Quit()
objWSheetToUse = Nothing
objWBookToUse = Nothing
'objExcel = Nothing
Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)