Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.access.modulesdaovba,microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 7
Default Run time error - Adding Workshet

I am using following procedure for adding worksheets in workbook, first time following function it works perfect and all the tab created alphabatically with the different name(abc, mno, stv, xys), but second time it give me following error

Method 'Move' of Object '_worksheet' failed;

If I comment following line, it wont give me error, it run perfectly except workbook tab name add in reverse chronolofical order like (xys, stv, mno, abc)

ExcelSht.Move befo=Worksheets(Worksheets.Count)

Lte me know whats wong I am doing? Or is there any way that I can sort worksheet alphabatically.

*--------------------------------------------------------
Dim ExcelApp As New Excel.Application
Dim ExcelSht As New Excel.Worksheet
Dim ExcelWkb As New Excel.Workbook
Dim rsManagersDis As New ADODB.Recordset

Set ExcelApp = CreateObject("Excel.Application")
MyExcel = True
ExcelApp.Visible = True

Set ExcelWkb = ExcelApp.Workbooks.Add

rsManagersDist.ActiveConnection = CurrentProject.Connection
rsManagersDist.CursorLocation = adUseClient
rsManagersDist.Open "Select distinct [Manager Name] rom tmpPMExcel order by [Manager Name] ) "

Do Until rsManagersDist.EOF
j2 = rsManagersDist("expr1")
Set ExcelSht = ExcelWkb.Worksheets.Add
ExcelWkb.Worksheets("Sheet1").Visible = xlSheetVeryHidden
ExcelSht.Visible = xlSheetVisible
ExcelSht.Move befo=Worksheets(Worksheets.Count)
ExcelSht.name = j2
ExcelSht.PageSetup.PrintGridlines = True
ExcelSht.PageSetup.Orientation = xlPortrait
rsManagersDist.MoveNext
Loop
*--------------------------------------------------------


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.601 / Virus Database: 382 - Release Date: 02/29/2004
  #2   Report Post  
Posted to microsoft.public.access.modulesdaovba,microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 3,885
Default Run time error - Adding Workshet

Hi
for sorting worksheets you may have a look at
http://www.cpearson.com/excel/sortws.htm

--
Regards
Frank Kabel
Frankfurt, Germany

Ashish Kanoongo wrote:
I am using following procedure for adding worksheets in workbook,
first time following function it works perfect and all the tab
created alphabatically with the different name(abc, mno, stv, xys),
but second time it give me following error

Method 'Move' of Object '_worksheet' failed;

If I comment following line, it wont give me error, it run perfectly
except workbook tab name add in reverse chronolofical order like
(xys, stv, mno, abc)

ExcelSht.Move befo=Worksheets(Worksheets.Count)

Lte me know whats wong I am doing? Or is there any way that I can
sort worksheet alphabatically.

*--------------------------------------------------------
Dim ExcelApp As New Excel.Application
Dim ExcelSht As New Excel.Worksheet
Dim ExcelWkb As New Excel.Workbook
Dim rsManagersDis As New ADODB.Recordset

Set ExcelApp = CreateObject("Excel.Application")
MyExcel = True
ExcelApp.Visible = True

Set ExcelWkb = ExcelApp.Workbooks.Add

rsManagersDist.ActiveConnection = CurrentProject.Connection
rsManagersDist.CursorLocation = adUseClient
rsManagersDist.Open "Select distinct [Manager Name] rom tmpPMExcel
order by [Manager Name] ) "

Do Until rsManagersDist.EOF
j2 = rsManagersDist("expr1")
Set ExcelSht = ExcelWkb.Worksheets.Add
ExcelWkb.Worksheets("Sheet1").Visible = xlSheetVeryHidden
ExcelSht.Visible = xlSheetVisible
ExcelSht.Move befo=Worksheets(Worksheets.Count)
ExcelSht.name = j2
ExcelSht.PageSetup.PrintGridlines = True
ExcelSht.PageSetup.Orientation = xlPortrait
rsManagersDist.MoveNext
Loop
*--------------------------------------------------------


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.601 / Virus Database: 382 - Release Date: 02/29/2004

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I expand/stretch one cell in an Excel workshet. No Time For Honey Do's Excel Discussion (Misc queries) 4 April 3rd 23 04:38 PM
excel workshet can not open in desktop [email protected] Excel Discussion (Misc queries) 1 November 10th 08 11:21 AM
Automatic extend row in workshet. Rao Ratan Singh New Users to Excel 0 February 4th 06 06:05 PM
Automatic extend row in workshet. Gary''s Student New Users to Excel 0 February 4th 06 02:37 PM
Run time error '-2147467259 (80004005) adding icon DMc2005 Excel Discussion (Misc queries) 3 October 2nd 05 04:39 PM


All times are GMT +1. The time now is 06:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"