can't edit Excel

qwertyjjj

Registered User.
Local time
Yesterday, 20:39
Joined
Aug 8, 2006
Messages
262
I'm trying to enter some values in some cells in an Excel spreadsheet as soon as it has been created but the following code doesn't seem to do anything (no errors either).

Am I missing a reference:

Private Sub cmd_Export_Click()
DoCmd.OutputTo acOutputForm, "Form1", acFormatXLS, "C:\Form1.xls", False
Dim objXL As Object

On Error Resume Next

Set objXL = GetObject(, "Excel.Application")
Set objXL = GetObject("C:\Form1.xls")

objXL.Application.Visible = True
objXL.Parent.Windows(1).Visible = True

objXL.Sheets("Form1").Select
objXL.Range("D1").Select
objXL.activecell.Value = 5
End Sub
 
qwertyjjj said:
(no errors either).....

On Error Resume Next

If you take out 'On Error Resume Next' then you might get an error.
 
oops.
Says ActiveX component can't create object on line:
Set objXL = GetObject(, "Excel.Application")
 
Well I know nothing about working with Excell because I avoid it like the plague but these 2 lines seem a bit odd.

Code:
Set objXL = GetObject(, "Excel.Application")
Set objXL = GetObject("C:\Form1.xls")

Have you tried this instead.

Code:
Set objXL = GetObject("C:\Form1.xls", "Excel.Application")

This is a complete stab in the dark so it may make no odds.
 
If you look in the Access help file it would seem to bear out what Cuttsy has written.

If Excel is registered on the machine, you can open with just:

Code:
Set objXL = GetObject("C:\Form1.xls")

If you want to use the full syntax, including the optional pathname, then Cuttsy's method:
Code:
Set objXL = GetObject("C:\Form1.xls", "Excel.Application")
would be the correct syntax.
 
Thanks.
Set objXL = GetObject("C:\Form1.xls", "Excel.Application")
I tried that and get the error File name or class name not found during Automation operation

STarngely enough, if I leave out the Excel.Application it works fine but then it seems to register it as an older version of Excel. So, when I try using things like Worksheet.Selection etc. it throws more errors

Edit: This is Access and Excel 2003 BTW
 
Last edited:
Like i said I dunno about VBA and excel but you might need to include a reference.
 
Here is code I use to print spreadsheets from and access application. It works. You could modify this method for editing; I have done it but cannot find the code now.

Dim ExcelObj As Object, i As Integer
Set ExcelObj = CreateObject("Excel.Application")
DoCmd.SetWarnings (False)
With ExcelObj.Application
.Workbooks.Open (DocPath)
.Application.Visible = False
For i = 1 To PCount
.ActiveSheet.PrintOut
Next i
.Quit
End With
Set ExcelObj = Nothing
DoCmd.SetWarnings (True)


Hope this helps.
 
Here is code I use to print spreadsheets from an access application. It works. You could modify this method for editing; I have done it but cannot find the code now.

Dim ExcelObj As Object, i As Integer
Set ExcelObj = CreateObject("Excel.Application")
DoCmd.SetWarnings (False)
With ExcelObj.Application
.Workbooks.Open (DocPath)
.Application.Visible = False
For i = 1 To PCount
.ActiveSheet.PrintOut
Next i
.Quit
End With
Set ExcelObj = Nothing
DoCmd.SetWarnings (True)


Hope this helps.
 
Open Excel

And mine. NB you need to have the correct References!
Code:
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open "H:\PORs\POR Template.xlt"
objExcel.Visible = False
objExcel.Sheets("DATA INPUT").Select
objExcel.Range("F3").Select
objExcel.ActiveCell.Value = CStr(Me.VendorCode)
objExcel.Range("F5").Select
objExcel.ActiveCell.Value = CStr(Me.nextPORid)
I'd suggest you keep excel.visible = False as it speeds up the code dramatically.
Also make sure the fields types match.
The code is slightly different for creating a new worksheet.
Code:
objExcel.Workbooks.Add "H:\PORs\NewWorksheetName.xls"
Hope you get a result.
B
 

Users who are viewing this thread

Back
Top Bottom