473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to show a message box that displays name for each worksheet in the excel file

14
I want this Access VBA to show a message box for each worksheet in the excel file. The MsgBox should say the worksheets name. HELP.

Expand|Select|Wrap|Line Numbers
  1. Sub ShowWorkSheets()
  2.     Dim xlApp As Excel.Application
  3.     Dim xlBook As Excel.Workbook
  4.     Dim xlSheet As Excel.Worksheet
  5.  
  6.  
  7. Set xlApp = New Excel.Application
  8. Set xlBook = xlApp.Workbooks.Open("L:\DOC-ADM\Business Analyst\Apr 08, FD SLA 2.xls")
  9.  
  10.   For Each xlSheet In xlBook
  11.         MsgBox xlSheet.Name
  12.  
  13.     Next xlSheet
  14.  
  15. End Sub
Oct 13 '10 #1
4 16798
MMcCarthy
14,534 Expert Mod 8TB
Change For Each xlSheet In xlBook to

Expand|Select|Wrap|Line Numbers
  1. For Each xlSheet In xlBook.Worksheets
Mary
Oct 13 '10 #2
hype261
207 100+
Try this code instead.

Expand|Select|Wrap|Line Numbers
  1. Sub ShowWorkSheets()
  2.     Dim xlApp As Excel.Application
  3.     Dim xlBook As Excel.Workbook
  4.     Dim xlSheet As Excel.Worksheet
  5.  
  6.  
  7.     Set xlApp = New Excel.Application
  8.     Set xlBook = xlApp.Workbooks.Open("L:\DOC-ADM\Business Analyst\Apr 08, FD SLA 2.xls")  
  9.  
  10.   For Each xlSheet In xlBook.Worksheets
  11.         MsgBox xlSheet.Name
  12.  
  13.     Next xlSheet
  14.  
  15. End Sub
Oct 13 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
Snap :D
Oct 13 '10 #4
ADezii
8,834 Expert 8TB
Should you want all Worksheet Names to appear in a single Message Box:
Expand|Select|Wrap|Line Numbers
  1. Dim xlApp As Excel.Application
  2. Dim xlBook As Excel.Workbook
  3. Dim xlSheet As Excel.Worksheet
  4. Dim strBuild As String
  5. Const conPATH_TO_EXCEL_WORKSHEET As String = "L:\DOC-ADM\Business Analyst\Apr 08, FD SLA 2.xls"
  6.  
  7.  
  8. Set xlApp = New Excel.Application
  9. Set xlBook = xlApp.Workbooks.Open(conPATH_TO_EXCEL_WORKSHEET)
  10.  
  11. For Each xlSheet In xlBook.Worksheets
  12.   strBuild = strBuild & xlSheet.Name & vbCrLf
  13. Next xlSheet
  14.  
  15. strBuild = Left$(strBuild, Len(strBuild) - 2)
  16.  
  17. MsgBox strBuild, vbInformation, "Worksheets in " & conPATH_TO_EXCEL_WORKSHEET
  18.  
  19. xlApp.Quit
Oct 13 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rick | last post by:
Hi, I just installed IIS and when I tried browsing the link: http://localhost it says: "you are not authorized to view this page" HTTP Error 403 - Forbidden
3
by: Girish Sahani | last post by:
hi ppl, Here is a simple function to remove those keys of a dictionary whose values are less than some specified value. But it isnt working. Please help. def prune(d,cp): l = for rule,value...
0
by: aBs0lut30 | last post by:
Hi Guys, I am working on a site and recently added several client callbacks to the project. Everything works GREAT while debugging the site in visual studio. Last night I copied the site up to our...
2
by: wudoug119 | last post by:
This is my code and it will take any number that I input and say it is a prime number. Please help me... int Prime(int prime) //declares isPrime as a function using integers { ...
1
by: hackerboy9523 | last post by:
this is what i am typing and it doesnt come up as code (i am using it on myspace)it just displays the code without the effect! <table> <tr><td>name</td><td>Game 1</td><td>game 2</td</tr>...
5
by: soheir | last post by:
am doing my first project so plz help i've created a submit button <input type="submit" onclick="valid()"> my function valid checks if the fields are not empty if empty a window prmpt appears...
0
by: John Sheppard | last post by:
Hello there, I have a checked list box which I am trying to save to my dataset. The last tickbox I edit before saving, doesnt actually get saved to the underlying binding source. I have...
2
by: nse111 | last post by:
I am trying to get some data and show it usig paging. my coding displays and also the paging is also visible on my web page. but it doesnt work. as in when i click next the next set of results aren't...
1
by: dougancil | last post by:
I have the following code: Imports System.IO Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.