I wasn't sure whether to post to the Access or Excel forum since I am using Access to call Excel. Went with Excel since this forum has way more viewers. Sorry if I got it wrong.
The following script runs fine the first time I click the command button on an Access form but after I close the Excel workbook and click the command button again to edit a new spreadsheet, I get the follow error message:
Run-time error '1004': Method "Columns' of object'_Global failed.
It fails here:
The script is being run from Access 2007 and is opening a spreadsheet in Excel 2007 (but using xls extension)
Been monkeying with code all morning and still no solution. Ideas anyone?
The following script runs fine the first time I click the command button on an Access form but after I close the Excel workbook and click the command button again to edit a new spreadsheet, I get the follow error message:
Run-time error '1004': Method "Columns' of object'_Global failed.
It fails here:
Code:
Columns("H:H").Select
The script is being run from Access 2007 and is opening a spreadsheet in Excel 2007 (but using xls extension)
Code:
Private Sub IdahotoExcel_Click()
Dim dlg As FileDialog
Dim idahofile As String
Dim xlApp As Object
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
With dlg
.Title = "Select the WADDL Excel file to import"
.InitialFileName = "S:\WildlifeHealth\Idaho\Incoming\"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "XLS", "*.xls*", 1
If .Show = True Then
idahofile = .SelectedItems(1)
End If
End With
xlApp.Workbooks.Open idahofile, True, False
Columns("H:H").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("H1").Select
ActiveCell.FormulaR1C1 = "WHNO"
Range("G1").Select
ActiveCell.FormulaR1C1 = "ClientID"
Range("I1").Select
ActiveCell.FormulaR1C1 = "Element"
'Set xlApp = Nothing
End Sub
Been monkeying with code all morning and still no solution. Ideas anyone?