G
Guest
In my MS-Access VBA code, I can open an Excel spreadsheet and change values
in specific cells based on values in my Access database. However, when that
cell value is a formula that includes a reference to a cell in a different
spreadsheet, the code blows up with:
Run-time error '1004': Application-defined or object-defined error
So, as best I can understand, Excel doesn't like to trust that there really
is a spreadsheet where I say there is, so it must ask the user to verify it.
When I do this manually, a file dialog window pops up and I have to drill
down in the folders to select the actual spreadsheet file, then Excel is
happy to accept the formula. However, when this is being done with VBA code,
it's sort of in an "unattended mode," so it cannot pop up the file dialog to
have the user verify the locaiton of the external file.
Here's a snippet of the code....
ExcelApp.Workbooks.Open fileName:=(sPath & rs("SourceFile")),
UpdateLinks:=False
ExcelApp.Range("F" & CStr(iX)).Select
ExcelApp.Selection.ClearContents
ExcelApp.ActiveCell.FormulaR1C1 = "='" & "[" & rs("ExcelFile") &
"]Clients'!$C$" & CStr(iX)
It bombs on that last statement. Again, the syntax used there works
elsewhere in the code where the value being stored does NOT contain a
reference to an external cell address. You can see the soft-coded references
based on values in my recordset. Any ideas?
in specific cells based on values in my Access database. However, when that
cell value is a formula that includes a reference to a cell in a different
spreadsheet, the code blows up with:
Run-time error '1004': Application-defined or object-defined error
So, as best I can understand, Excel doesn't like to trust that there really
is a spreadsheet where I say there is, so it must ask the user to verify it.
When I do this manually, a file dialog window pops up and I have to drill
down in the folders to select the actual spreadsheet file, then Excel is
happy to accept the formula. However, when this is being done with VBA code,
it's sort of in an "unattended mode," so it cannot pop up the file dialog to
have the user verify the locaiton of the external file.
Here's a snippet of the code....
ExcelApp.Workbooks.Open fileName:=(sPath & rs("SourceFile")),
UpdateLinks:=False
ExcelApp.Range("F" & CStr(iX)).Select
ExcelApp.Selection.ClearContents
ExcelApp.ActiveCell.FormulaR1C1 = "='" & "[" & rs("ExcelFile") &
"]Clients'!$C$" & CStr(iX)
It bombs on that last statement. Again, the syntax used there works
elsewhere in the code where the value being stored does NOT contain a
reference to an external cell address. You can see the soft-coded references
based on values in my recordset. Any ideas?