LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Late binding to Excel from Access causing Object error

2003

Assume Access just completed VBA transfering 21 Tables to 21 XL spreadsheets
on One workbook.

Then, via Automation, I wish to format all 21 sheets in the XLS w/b file.

The Automation For Next loop does not cycle through all W/S's in the XL w/b
file. It just formats the first w/s 21 times.

I then thought that maybe I needed to save the XL w/b with 21 sheets first,
then attempt to format all of them.

At EOD, I want to have all 21 sheets in one w/b looped through the
FormatXLSheets Sub.

My Automation code (99% Dev Ashish's Automation Code) follows:

Would someone review my code to ascertain why it does not sequence through
to 21 XL w/s?

Dave Hargis, Microsoft Access MVP AKA Klatuu, feels that the late binding
and after Dimming: Dim wks As Object, is causing VBA

Then the following loop does not work (does not cycle through all sheets -
loops through sheet1 21 times) because VBA is not sure what to do with
"wks" as Dimmed As Object vs Dimmed as Worksheet.

For Each wks in Worksheets

Next wks

Any work-arounds; additional thoughts?

TIA EagleOne
************************************************** **

Sub FormatXLSheets(myPathFile As String, myFileName As String)
'
'Code Courtesy of Dev Ashish
'
Dim objXL As Object
Dim strWhat As String, boolXL As Boolean
Dim objActiveWkb As Object

' Variables related to Excel Formatting
Dim wks As Object
Dim myRange As Object
Dim myRange2 As Object
Dim myCell As Object
Dim myRowsToProcess As Long
Dim myColumnsToProcess As Long
Dim MaxRows As Long
Dim MaxColumns As Long

If fIsAppRunning("Excel") Then
Set objXL = GetObject(, "Excel.Application")
boolXL = False
Else
Set objXL = CreateObject("Excel.Application")
boolXL = True
End If

With objXL.Application
..Visible = False
..workbooks.Open myPathFile
End With
Set objActiveWkb = objXL.Application.ActiveWorkBook

With objActiveWkb
'
Set wks = Nothing
For Each wks In .worksheets
With wks
MaxRows = .Rows.Count
MaxColumns = .Columns.Count
End With
'
'
'
' (Series of formatting steps in Excel
'
'

Cells.EntireColumn.AutoFit
Range("A1").Select
Next wks
End With

objActiveWkb.Close savechanges:=True

'If boolXL Then objXL.Application.Quit

objXL.Application.Quit

Set objActiveWkb = Nothing: Set objXL = Nothing

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query causing #ref error in spreadsheet endro Excel Discussion (Misc queries) 0 May 14th 08 12:03 AM
VLOOKUP Formula causing an error japc90 Excel Discussion (Misc queries) 2 July 25th 06 11:36 PM
Excel Hyperlink to specific Access object Karla V Excel Discussion (Misc queries) 0 July 1st 05 02:35 PM
Access privilege problem with Excel object Wellie Setting up and Configuration of Excel 0 April 8th 05 01:35 PM
VB Extensibility library and "late binding" Dennis Excel Discussion (Misc queries) 0 March 30th 05 10:51 PM


All times are GMT +1. The time now is 04:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"