Hello,
Could you please tell me how to write a VB script using/with COM to open an excel sheet, modify the data and close the excel sheet. Is it possible to create COM objects/add-ins with VBA?
I have used Excel VBA script to open an Excel sheet, modify/insert the data and close the Excel sheet. Below is my code. Is it possible to reuse this code to produce the same end result but using COM object ?
############################################################
Private Sub CommandButton1_Click()
Dim xniku As New Excel.Application
Dim xdime As New Excel.Application
Dim icountn As Range
Dim icountd As Range
Dim totalrowsdim As Range
Dim user_named As String
Dim user_namen As String
Dim niku_state As String
Dim resource_id As String
Dim first_name As String
Dim last_name As String
Dim dim_product As String
Dim k As Integer
k = 0
xdime.Workbooks.Open "D:\Dimensions.xls"
MsgBox icountd.Rows.Count
For i = 2 To icountd.Rows.Count
user_named = xdime.ActiveSheet.Cells(i, 1)
MsgBox user_named
dim_product = xdime.ActiveSheet.Cells(i, 2)
MsgBox dim_product
xniku.Workbooks.Open "D:\Nikuclarity.xls"
Set icountn = Range("A1:B1", Range("A1").End(xlDown))
MsgBox icountn.Rows.Count
For j = 2 To icountn.Rows.Count
user_namen = xniku.ActiveSheet.Cells(j, 1)
MsgBox user_namen
If user_namen = user_named Then
MsgBox "both are equal"
xniku.ActiveSheet.Cells(6, i) = dim_product
End If
Next j
Next i
xniku.ActiveWorkbook.Save
xniku.Quit
xdime.ActiveWorkbook.Save
Set xniku = Nothing
End Sub
############################################################
Apologies if my questions are not clear. Appreciate your help……………
Thanks
Could you please tell me how to write a VB script using/with COM to open an excel sheet, modify the data and close the excel sheet. Is it possible to create COM objects/add-ins with VBA?
I have used Excel VBA script to open an Excel sheet, modify/insert the data and close the Excel sheet. Below is my code. Is it possible to reuse this code to produce the same end result but using COM object ?
############################################################
Private Sub CommandButton1_Click()
Dim xniku As New Excel.Application
Dim xdime As New Excel.Application
Dim icountn As Range
Dim icountd As Range
Dim totalrowsdim As Range
Dim user_named As String
Dim user_namen As String
Dim niku_state As String
Dim resource_id As String
Dim first_name As String
Dim last_name As String
Dim dim_product As String
Dim k As Integer
k = 0
xdime.Workbooks.Open "D:\Dimensions.xls"
MsgBox icountd.Rows.Count
For i = 2 To icountd.Rows.Count
user_named = xdime.ActiveSheet.Cells(i, 1)
MsgBox user_named
dim_product = xdime.ActiveSheet.Cells(i, 2)
MsgBox dim_product
xniku.Workbooks.Open "D:\Nikuclarity.xls"
Set icountn = Range("A1:B1", Range("A1").End(xlDown))
MsgBox icountn.Rows.Count
For j = 2 To icountn.Rows.Count
user_namen = xniku.ActiveSheet.Cells(j, 1)
MsgBox user_namen
If user_namen = user_named Then
MsgBox "both are equal"
xniku.ActiveSheet.Cells(6, i) = dim_product
End If
Next j
Next i
xniku.ActiveWorkbook.Save
xniku.Quit
xdime.ActiveWorkbook.Save
Set xniku = Nothing
End Sub
############################################################
Apologies if my questions are not clear. Appreciate your help……………
Thanks