you will need microsoft excel 11.0 object library reference added to your project.
so first lets make the excel application:
Dim XcLApp As Object
Dim XcLWB As Object
Dim XcLWS As Object
Dim XcLRNG As Object
Set XcLApp = CreateObject("Excel.Application")
Set XcLWB = XcLApp.Workbooks.Add
Set XcLWS = XcLWB.Worksheets.Add
by now you have the app. open and ready to use
XcLApp is for excel application
XcLWB is for the workbook
XcLWS is for sheet
so we create an excel app and add a workbook with sheetbook
now we need to pass the symbols to excel. as you know excel have letters for column headers so when you
want to send something to col 1 row 1 you need to send it to excel range A 1. A for column header and 1 for
row.
so here is how to send something to row 1 col 1 in excel
first lest prepare the cols and rows to send it
Public Function Addres_Excel(ByVal lng_row As Long, ByVal lng_col As Long) As String
Dim modval As Long
Dim strval As String
modval = (lng_col - 1) Mod 26
strval = Chr$(Asc("A") + modval)
modval = ((lng_col - 1) \ 26) - 1
If modval >= 0 Then strval = Chr$(Asc("A") + modval) & strval
Addres_Excel = strval & lng_row
End Function
this function make col1 look like A and send as result "A1" for col1 and row 1. what it do is divide on 26 (26 like
the 26 letters in engl. alphabet) get the reminder. then it sum the ascii code for "A" with the result forom
devision and return it as symbol. for example if it is col. 1 we will send in lng_col=1 then modval will be 0.
0+ascii code for "A" will return as string "A". if we send 2 for lng_col it will return "B" and so on.
so if we want to send "Test String" in excell try this. the if in function Addres_Excel() is for addresses like
"AA" etc.
Private Sub Command1_Click()
Dim XcLApp As Object
Dim XcLWB As Object
Dim XcLWS As Object
Set XcLApp = CreateObject("Excel.Application")
Set XcLWB = XcLApp.Workbooks.Add
Set XcLWS = XcLWB.Worksheets.Add
XcLWS.Range(Addres_Excel(1, 1)).Value = "Test string"
XcLApp.Visible = True
End Sub
Public Function Addres_Excel(ByVal lng_row As Long, ByVal lng_col As Long) As String
Dim modval As Long
Dim strval As String
modval = (lng_col - 1) Mod 26
strval = Chr$(Asc("A") + modval)
modval = ((lng_col - 1) \ 26) - 1
If modval >= 0 Then strval = Chr$(Asc("A") + modval) & strval
Addres_Excel = strval & lng_row
End Function
so here it is
Attached File(s)
-
excel.zip (2.6K)
Number of downloads: 2167





MultiQuote











|