Excel Constants in VB.net
Trying to convert a piece of vb code to dotnet , basically copying and pasting some stuff in excel , i had recorded a macro and pasted that code on VB and it was working fine, now the same code am tweeking to make it work on dotnet, ON XL CONSTANTS GETTING ERROR.. NOT DEFINED.
VB Code
*******************
xlRpt.ActiveWorkbook.Worksheets(i).Activate()
xlRpt.Cells.Select()
xlRpt.Selection.Copy()
xlRpt.Selection.PasteSpecial(Paste:=xlValues,operation:=xlNone, SkipBlanks:= False, Transpose:=False)
xlRpt.Application.CutCopyMode = False
VB.net code
***************
CType(xlRpt.ActiveWorkbook.Worksheets(i), xlRpt.Worksheet).Activate()
xlRpt.Cells.Select()
CType(xlRpt.Selection, Excel.Range).Copy()
xlRpt.Selection.PasteSpecial(Paste:=-4163, Operation:=xlNone, SkipBlanks:= False, Transpose:=False)
xlRpt.Selection.PasteSpecial(Paste:=xlValues, Operation:=xlNone, SkipBlanks:= False, Transpose:=False)
xlRpt.Application.CutCopyMode = False
'ABOVE ON xlValues and xlNone it tells 'Variables not defined'
HELP !!!!!!!!
Thanks in Advance.
Re: Excel Constants in VB.net
Use the following:
Dim xlRpt = CreateObject("Excel.Application")
Dim xlB as object
Dim Xls as Excel.Worksheet
xlB=XlRpt.Workbooks.Open("Enter Excel File Path and Name here") 'for opening an existing file
xlS=CType(xlB.Worksheets(i), Excel.Worksheet)
xlS.Range("A1:E5").Copy 'Copies Cells A1 through E5 to the clipoard
xlS.Range("G1").PasteSpecial(Paste:=xlValues,operation:=xlNone, SkipBlanks:= False, Transpose:=False) ' Paste it in Cell G1.
.
.
.
to exit XlRpt,
xlS=nothing
xlB.close(false)
xlB=nothing
XlRpt.quit
XlRpt=nothing
Good luck
Re: Excel Constants in VB.net
but still you are using the same constants (xlValues , xlNone, etc) which were problem variables for me.
-sihikahi
Re: Excel Constants in VB.net
OK. Try this:
xlS.Range("J6").PasteSpecial(Excel.XlPasteType.xlPasteValues, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, False, False)
If you open 'object view' under 'view' menu, and select ExcelInterop, you will find definitions of all properties under PasteSpecial. Hope this helps.
Re: Excel Constants in VB.net