PC Review


Reply
Thread Tools Rate Thread

How Do I Assign a Workbook to an Object Variable?

 
 
Dan
Guest
Posts: n/a
 
      23rd Jun 2004
Using Access 2003 VBA, how do I open a Excel Workbook and then assign it
to an Excel.Workbook object variable so it is easily referenced?

TIA,
Dan
 
Reply With Quote
 
 
 
 
Dave Jones
Guest
Posts: n/a
 
      23rd Jun 2004
Try:

On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
Err.Clear
If objXL Is Nothing Then
Set objXL = CreateObject("Excel.Application")
End If
Set Mybook = objXL.Workbooks.Add

And then you can access the workbook using:
Mybook.Sheets("Sheet1").Select
And then access that sheet as follows:
objXL.Rows("1").Select
objXL.Selection.Font.Bold = True

Dave

"Dan" <dan@nospam..com> wrote in message
news:(E-Mail Removed)...
> Using Access 2003 VBA, how do I open a Excel Workbook and then assign it
> to an Excel.Workbook object variable so it is easily referenced?
>
> TIA,
> Dan



 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      24th Jun 2004
I actually want to open an existing workbook, say c:\test\mybook.xls,
and assign it to object variable to manipulate. I can't seem to get the
syntax correct...


On 6/23/2004 5:51 PM, Dave Jones wrote:
> Try:
>
> On Error Resume Next
> Set objXL = GetObject(, "Excel.Application")
> Err.Clear
> If objXL Is Nothing Then
> Set objXL = CreateObject("Excel.Application")
> End If
> Set Mybook = objXL.Workbooks.Add
>
> And then you can access the workbook using:
> Mybook.Sheets("Sheet1").Select
> And then access that sheet as follows:
> objXL.Rows("1").Select
> objXL.Selection.Font.Bold = True
>
> Dave
>
> "Dan" <dan@nospam..com> wrote in message
> news:(E-Mail Removed)...
>
>>Using Access 2003 VBA, how do I open a Excel Workbook and then assign it
>>to an Excel.Workbook object variable so it is easily referenced?
>>
>>TIA,
>>Dan

>
>
>

 
Reply With Quote
 
Dave Jones
Guest
Posts: n/a
 
      24th Jun 2004
Try:
Set Mybook=objXL.Workbooks.Add("C:\Test\Mybook.xls")

Dave

"Dan" <dan@nospam..com> wrote in message
news:(E-Mail Removed)...
> I actually want to open an existing workbook, say c:\test\mybook.xls,
> and assign it to object variable to manipulate. I can't seem to get the
> syntax correct...
>
>
> On 6/23/2004 5:51 PM, Dave Jones wrote:
> > Try:
> >
> > On Error Resume Next
> > Set objXL = GetObject(, "Excel.Application")
> > Err.Clear
> > If objXL Is Nothing Then
> > Set objXL = CreateObject("Excel.Application")
> > End If
> > Set Mybook = objXL.Workbooks.Add
> >
> > And then you can access the workbook using:
> > Mybook.Sheets("Sheet1").Select
> > And then access that sheet as follows:
> > objXL.Rows("1").Select
> > objXL.Selection.Font.Bold = True
> >
> > Dave
> >
> > "Dan" <dan@nospam..com> wrote in message
> > news:(E-Mail Removed)...
> >
> >>Using Access 2003 VBA, how do I open a Excel Workbook and then assign it
> >>to an Excel.Workbook object variable so it is easily referenced?
> >>
> >>TIA,
> >>Dan

> >
> >
> >



 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      24th Jun 2004
That did it. Thanks, Dan

On 6/24/2004 12:00 PM, Dave Jones wrote:

> Try:
> Set Mybook=objXL.Workbooks.Add("C:\Test\Mybook.xls")
>
> Dave
>
> "Dan" <dan@nospam..com> wrote in message
> news:(E-Mail Removed)...
>
>>I actually want to open an existing workbook, say c:\test\mybook.xls,
>>and assign it to object variable to manipulate. I can't seem to get the
>>syntax correct...
>>
>>
>>On 6/23/2004 5:51 PM, Dave Jones wrote:
>>
>>>Try:
>>>
>>>On Error Resume Next
>>>Set objXL = GetObject(, "Excel.Application")
>>>Err.Clear
>>>If objXL Is Nothing Then
>>> Set objXL = CreateObject("Excel.Application")
>>> End If
>>>Set Mybook = objXL.Workbooks.Add
>>>
>>>And then you can access the workbook using:
>>>Mybook.Sheets("Sheet1").Select
>>>And then access that sheet as follows:
>>>objXL.Rows("1").Select
>>>objXL.Selection.Font.Bold = True
>>>
>>>Dave
>>>
>>>"Dan" <dan@nospam..com> wrote in message
>>>news:(E-Mail Removed)...
>>>
>>>
>>>>Using Access 2003 VBA, how do I open a Excel Workbook and then assign it
>>>>to an Excel.Workbook object variable so it is easily referenced?
>>>>
>>>>TIA,
>>>>Dan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
assign objects into array or object variable? Fendic Microsoft Excel Programming 1 22nd Jul 2005 09:23 PM
Add new worksheet and assign it to an object variable? Thief_ Microsoft Excel Programming 2 4th Apr 2005 07:21 AM
How do I assign a report to an object variable? =?Utf-8?B?U2ltb24gQ2xlYWw=?= Microsoft Access VBA Modules 3 17th Mar 2005 03:59 PM
FileSearch Object - Cannot assign to variable Alan Microsoft Excel Programming 1 24th Jan 2005 03:41 AM
Variable type Object, assign to a Class at runtime Andres Microsoft VB .NET 4 10th Sep 2003 09:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:44 AM.