Hi VBA gurus,
Sorry for my very limited VBA skill level in access especially when need to work on Excel automation. I need to write a function in Access vba to delete entire column or columns and shift lef in Excel. After delete the column(s), it will save the change. This function can be reused so it will allow me to pass parameters - Excel file name, sheet name, and column number(column ranges).
I tried but my code does not work. Any help will be greatly appreciated ! Thank you very much!
Public Sub DeleteColumn(ByVal bookname As String, ByVal sheetname As String, ByVal cellcolumn As String) 'does not work
Dim oXL As Excel.Application
Dim oSheet As Excel.Worksheet
Dim oWKSource As Excel.Workbook
Dim strSourceBook As String
Dim strSourceSheet As String
Dim raSource As Excel.Range
strSourceBook = bookname
strSourceSheet = sheetname
Set oXL = CreateObject("Excel.Application")
Set oWKSource = oXL.Workbooks.Open(strSourceBook)
Set oSheet = oWKSource.Worksheets(strSourceSheet)
oXL.Visible = False
oXL.DisplayAlerts = False
oWKSource.Worksheets(strSourceSheet).Range(cellcolumn).EntireColumn.Delete xlShiftToLeft
oXL.DisplayAlerts = False
'Close all workbooks
For Each oBook In oXL.Workbooks
oBook.Close False
Next
oXL.DisplayAlerts = True
oXL.Quit
Set oXL = Nothing
Set oWKSource = Nothing
Set oWKDestination = Nothing
Set oBook = Nothing
End Sub
Sorry for my very limited VBA skill level in access especially when need to work on Excel automation. I need to write a function in Access vba to delete entire column or columns and shift lef in Excel. After delete the column(s), it will save the change. This function can be reused so it will allow me to pass parameters - Excel file name, sheet name, and column number(column ranges).
I tried but my code does not work. Any help will be greatly appreciated ! Thank you very much!
Public Sub DeleteColumn(ByVal bookname As String, ByVal sheetname As String, ByVal cellcolumn As String) 'does not work
Dim oXL As Excel.Application
Dim oSheet As Excel.Worksheet
Dim oWKSource As Excel.Workbook
Dim strSourceBook As String
Dim strSourceSheet As String
Dim raSource As Excel.Range
strSourceBook = bookname
strSourceSheet = sheetname
Set oXL = CreateObject("Excel.Application")
Set oWKSource = oXL.Workbooks.Open(strSourceBook)
Set oSheet = oWKSource.Worksheets(strSourceSheet)
oXL.Visible = False
oXL.DisplayAlerts = False
oWKSource.Worksheets(strSourceSheet).Range(cellcolumn).EntireColumn.Delete xlShiftToLeft
oXL.DisplayAlerts = False
'Close all workbooks
For Each oBook In oXL.Workbooks
oBook.Close False
Next
oXL.DisplayAlerts = True
oXL.Quit
Set oXL = Nothing
Set oWKSource = Nothing
Set oWKDestination = Nothing
Set oBook = Nothing
End Sub