ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting an existing worksheet (https://www.excelbanter.com/excel-programming/419523-selecting-existing-worksheet.html)

SQLScott

Selecting an existing worksheet
 
Good afternoon,

Based on the following Microsoft article, I am retrieving data from SQL
Server.

http://msdn.microsoft.com/en-us/library/bb964684.aspx

What this article does is create a a new Excel worksheet and populate that
sheet with the data (roughly on page 13 of document).

employeeWS = DirectCast(Me.Application.Sheets.Add(), Excel.Worksheet)
employeeWS.Name = "Employees"

I want to use an EXISTING worksheet, but I cannot get this to work. I have
tried several options, such as using:

Me.Application.Sheets("employee").Select

But it either bombs there or on subsequent code (depending on other options
I try).

I don't want to create a NEW worksheet so how do I use the existing
worksheet (the one that has the focus).

Thanks in advance. It is greatly appreciated.


--
Thanks,

Scott

Mike H

Selecting an existing worksheet
 
Hi,

Maybe this

Set employeeWS = ActiveSheet
employeeWS.Name = "Employees"

Mike

"SQLScott" wrote:

Good afternoon,

Based on the following Microsoft article, I am retrieving data from SQL
Server.

http://msdn.microsoft.com/en-us/library/bb964684.aspx

What this article does is create a a new Excel worksheet and populate that
sheet with the data (roughly on page 13 of document).

employeeWS = DirectCast(Me.Application.Sheets.Add(), Excel.Worksheet)
employeeWS.Name = "Employees"

I want to use an EXISTING worksheet, but I cannot get this to work. I have
tried several options, such as using:

Me.Application.Sheets("employee").Select

But it either bombs there or on subsequent code (depending on other options
I try).

I don't want to create a NEW worksheet so how do I use the existing
worksheet (the one that has the focus).

Thanks in advance. It is greatly appreciated.


--
Thanks,

Scott


SQLScott

Selecting an existing worksheet
 
No, but you gave pointed me down the right path. It is this:

employeeWS = DirectCast(Me.Application.ActiveSheet, Excel.Worksheet)
employeeWS.Name = "Employees"

Thanks for your help Mike! Greatly appreciated.
--
Thanks,

Scott


"Mike H" wrote:

Hi,

Maybe this

Set employeeWS = ActiveSheet
employeeWS.Name = "Employees"

Mike

"SQLScott" wrote:

Good afternoon,

Based on the following Microsoft article, I am retrieving data from SQL
Server.

http://msdn.microsoft.com/en-us/library/bb964684.aspx

What this article does is create a a new Excel worksheet and populate that
sheet with the data (roughly on page 13 of document).

employeeWS = DirectCast(Me.Application.Sheets.Add(), Excel.Worksheet)
employeeWS.Name = "Employees"

I want to use an EXISTING worksheet, but I cannot get this to work. I have
tried several options, such as using:

Me.Application.Sheets("employee").Select

But it either bombs there or on subsequent code (depending on other options
I try).

I don't want to create a NEW worksheet so how do I use the existing
worksheet (the one that has the focus).

Thanks in advance. It is greatly appreciated.


--
Thanks,

Scott



All times are GMT +1. The time now is 05:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com