PC Review


Reply
Thread Tools Rate Thread

Access ->Excel, how to create a workbook and worksheet

 
 
=?Utf-8?B?SmFuaXM=?=
Guest
Posts: n/a
 
      3rd Nov 2007
I have this snippet which works to open the named workbook and tab.

Set appExcel = Excel.Application
appExcel.Visible = True
Set wbk = appExcel.Workbooks.Open("emp.xls")
Set wks = appExcel.Worksheets("Employees1")
What I need is to know how to create the workbook and sheet in Access/VBA if
the workbook/sheet do not exist? If possible can you give me an example? I
tried the Create method instead of Open and tried to Add a worksheet named
Employees1 and it didn't work.
tia,
-----------------

Set appExcel = Excel.Application
appExcel.Visible = True
Set wbk = appExcel.Workbooks.Create("emp1.xls")

Set wks = appExcel.Worksheets.Add("Employees1")
wks.Activate

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFuaXM=?=
Guest
Posts: n/a
 
      4th Nov 2007
I will reword this to make it simpler to understand. Sorry.

"Janis" wrote:

> I have this snippet which works to open the named workbook and tab.
>
> Set appExcel = Excel.Application
> appExcel.Visible = True
> Set wbk = appExcel.Workbooks.Open("emp.xls")
> Set wks = appExcel.Worksheets("Employees1")
> What I need is to know how to create the workbook and sheet in Access/VBA if
> the workbook/sheet do not exist? If possible can you give me an example? I
> tried the Create method instead of Open and tried to Add a worksheet named
> Employees1 and it didn't work.
> tia,
> -----------------
>
> Set appExcel = Excel.Application
> appExcel.Visible = True
> Set wbk = appExcel.Workbooks.Create("emp1.xls")
>
> Set wks = appExcel.Worksheets.Add("Employees1")
> wks.Activate
>

 
Reply With Quote
 
Arvin Meyer [MVP]
Guest
Posts: n/a
 
      4th Nov 2007
Try:

Set wbk = appExcel.Workbooks.Add
' add the sheet and data then
appExcel.SaveAs "C:\MyFolder\emp1.xls"
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Janis" <(E-Mail Removed)> wrote in message
news:281E598E-6620-48E6-8B98-(E-Mail Removed)...
>I will reword this to make it simpler to understand. Sorry.
>
> "Janis" wrote:
>
>> I have this snippet which works to open the named workbook and tab.
>>
>> Set appExcel = Excel.Application
>> appExcel.Visible = True
>> Set wbk = appExcel.Workbooks.Open("emp.xls")
>> Set wks = appExcel.Worksheets("Employees1")
>> What I need is to know how to create the workbook and sheet in Access/VBA
>> if
>> the workbook/sheet do not exist? If possible can you give me an example?
>> I
>> tried the Create method instead of Open and tried to Add a worksheet
>> named
>> Employees1 and it didn't work.
>> tia,
>> -----------------
>>
>> Set appExcel = Excel.Application
>> appExcel.Visible = True
>> Set wbk = appExcel.Workbooks.Create("emp1.xls")
>>
>> Set wks = appExcel.Worksheets.Add("Employees1")
>> wks.Activate
>>



 
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
Converting Excel Workbook with 36 colmns per worksheet to Access KenV Microsoft Access Database Table Design 3 6th Oct 2009 02:46 AM
Create new workbook and new worksheet and close. Worksheet not saved Patrick Microsoft Excel Programming 1 25th Jul 2009 07:00 PM
Create a new excel workbook from access ST Microsoft Excel Misc 1 31st Jul 2006 04:15 PM
Adding Excel Worksheet to existing Workbook using Access 97 Macro Mike F via AccessMonster.com Microsoft Access Macros 3 22nd Jul 2005 10:02 PM
EXCEL: Find data in worksheet and create a new sheet in same workbook Peacce Dog Microsoft Excel Programming 3 18th Nov 2004 08:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:59 PM.