473,385 Members | 1,279 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,385 software developers and data experts.

Need to get the last worksheet name in msgbox

Hi,
I need to get the last (rightmost worksheet) name in msgbox. I used Sheets(Sheets.Count) to get last sheet. But its only giving first sheets name. Kindly help me on this. Here is my code.
Expand|Select|Wrap|Line Numbers
  1. Sub ShowMRNumber()
  2.     Dim xlApp As Excel.Application
  3.     Dim xlBook As Excel.Workbook
  4.     Dim xlSheet As Excel.Worksheet
  5.  
  6.     Set xlApp = New Excel.Application
  7.     Set xlBook = xlApp.Workbooks.Open("location")
  8.     Set xlSheet = xlApp.Sheets(Sheets.Count)
  9.  
  10.         MsgBox "MR No. is" & vbNewLine xlSheet.Name
  11.  
  12. xlApp.Workbooks.Close
  13.  
  14. End Sub
May 19 '17 #1

✓ answered by NeoPa

In your line #8 you have two references to Sheets. Both seem incorrect to me.

One is listed as a property of the application and the other has no object reference at all.

I would expect to see :
Expand|Select|Wrap|Line Numbers
  1.     Set xlSheet = xlBook.Sheets(xlBook.Sheets.Count)

2 862
MikeTheBike
639 Expert 512MB
Hi

Apart from the syntax error in the MsgBox statement, I currently cannot see why this does not result in the last (Right) sheet name being returned.

If you get the first sheet name using this, what do get if you use xlApp.Sheets(1).Name ?


MTB
May 19 '17 #2
NeoPa
32,556 Expert Mod 16PB
In your line #8 you have two references to Sheets. Both seem incorrect to me.

One is listed as a property of the application and the other has no object reference at all.

I would expect to see :
Expand|Select|Wrap|Line Numbers
  1.     Set xlSheet = xlBook.Sheets(xlBook.Sheets.Count)
May 19 '17 #3

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

Similar topics

8
by: Vanessa | last post by:
Hi In my VB Dot Net program, I'm using Automation to call Excel worksheet to do some insert some data. I have rename my worksheet to a name. eg. "ABC". How do I insert the worksheet name &...
4
by: Anthony Cuttitta Jr. | last post by:
I'm working on some procedures where Access queries are exported to Excel, and then later on, those same workbooks are openned, and I need to target a specific original sheet. Sometimes there will...
5
by: Theresa Hancock via AccessMonster.com | last post by:
I have an Excel table I need to import into Access. The name is entered into one field "Name". I'd like to have two fields in Access, FirstName and LastName. How do I do this. -- Message posted...
1
by: Mike P | last post by:
How do get at the name of an Excel worksheet in C#? Any help would be really appreciated. Cheers, Mike
0
by: dave1 | last post by:
Probably an easy question for some. I'm trying to read the worksheet name, then use that name as a variable reference. Got this to work as a function with evaluate: function A() A = "255 plus...
2
by: slmclc77 | last post by:
What's the easiest way to get the worksheet name into a cell in the worksheet, such that any time the worksheet name is changed, that change is reflected in the cell in the worksheet? I tried...
1
by: kunalgujar | last post by:
How can we rename a excel worksheet name in ASP.. The worksheet takes the name of the excel file only, but I dont want tat...i want 2 have my own name for the worksheet...... Can some one put the...
1
by: sayedul | last post by:
Hi, I can access data from xls file using OpenDataSource. But if the worksheet name starts with numeric character it gives error. Scripts are as follows: If the worksheet name is 'Sheet1' it...
3
by: Andrea Raimondi | last post by:
Hello peers! I'm working on this application and I'm in need for some thoughtful advice :-p I have an SQLDataSource with params, select, etc. One of my params is the table name, which can be...
14
by: SunnyC | last post by:
I have a table as below in test.mdb Access database. on a form, I want to use lookup to capture the the last field name in a text on the form, in this case, it is 200906. by using some code I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.