472,811 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 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 16605
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

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.