A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Need help in setting active Excel work sheet in VB6.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 10th 06, 12:06 AM posted to microsoft.public.outlook.program_vba
Craigbob
external usenet poster
 
Posts: 1
Default Need help in setting active Excel work sheet in VB6.

Hi all,

I'm using the code below to open a work book and move to a particular
worksheet in the work book.

The problem arises in the Else Clause of the IF Then statement. I'm not sure
how to set Excel to a particular sheet in the workbook, even though I have
both the name of the sheet and the number of the sheet.

The work books can have either 1 or 2 worksheets in them. If it is 1 sheet,
there is no problem. If there the workbook has 2 sheets I want to set the 2nd
sheet as the active sheet.

Any help is appreciated.

Thanks

Craig


Public Function OpenWorkbook(strFilename) As String
' Comments : Open an Excel workbook and returns the FSR Type.
' Parameters: DocumentName - Path and file name to open
' Returns : FSR Type (Old or New)
'
Dim strFSRType As String
Dim xlActiveSheet As Excel.Worksheet

On Error GoTo PROC_ERR

Set m_Excel = CreateObject("EXCEL.APPLICATION")
Set m_Workbook = m_Excel.Workbooks.Open(strFilename)
Set xlActiveSheet = m_Workbook.ActiveSheet


If xlActiveSheet.Name = "main" Then
'ActiveWorkbook.Sheets.Count
OpenWorkbook = "Old"
Else
OpenWorkbook = "New"
xlActiveSheet = m_Workbook.Sheets("FSR - 45043 Report Sheet")
End If

PROC_EXIT:
Exit Function

PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume PROC_EXIT

End Function

  #2  
Old October 10th 06, 06:40 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Need help in setting active Excel work sheet in VB6.

Am Mon, 9 Oct 2006 16:06:01 -0700 schrieb Craigbob:

For obect variables you need the Set statement:

Set xlActiveSheet = ...

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


Hi all,

I'm using the code below to open a work book and move to a particular
worksheet in the work book.

The problem arises in the Else Clause of the IF Then statement. I'm not

sure
how to set Excel to a particular sheet in the workbook, even though I have
both the name of the sheet and the number of the sheet.

The work books can have either 1 or 2 worksheets in them. If it is 1

sheet,
there is no problem. If there the workbook has 2 sheets I want to set the

2nd
sheet as the active sheet.

Any help is appreciated.

Thanks

Craig


Public Function OpenWorkbook(strFilename) As String
' Comments : Open an Excel workbook and returns the FSR Type.
' Parameters: DocumentName - Path and file name to open
' Returns : FSR Type (Old or New)
'
Dim strFSRType As String
Dim xlActiveSheet As Excel.Worksheet

On Error GoTo PROC_ERR

Set m_Excel = CreateObject("EXCEL.APPLICATION")
Set m_Workbook = m_Excel.Workbooks.Open(strFilename)
Set xlActiveSheet = m_Workbook.ActiveSheet


If xlActiveSheet.Name = "main" Then
'ActiveWorkbook.Sheets.Count
OpenWorkbook = "Old"
Else
OpenWorkbook = "New"
xlActiveSheet = m_Workbook.Sheets("FSR - 45043 Report Sheet")
End If

PROC_EXIT:
Exit Function

PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume PROC_EXIT

End Function

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
shortcut in excel sheet to and Outlook email Finny Outlook - General Queries 2 September 29th 06 04:00 PM
How do I Autopopulate an Outlook form from an Excel Sheet? AttyBhai Outlook - Using Forms 1 September 19th 06 01:18 PM
Send email to email addressess in Excel Sheet Darrell Outlook - Using Contacts 2 September 18th 06 12:20 PM
Setting in OE tools dosen't work Jack Nation Outlook Express 6 August 15th 06 06:50 AM
How can I extract share calender information to excel sheet TILLYCHIPS Outlook - Calandaring 1 April 17th 06 03:37 PM


All times are GMT +1. The time now is 09:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.