Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem in updating all worksheets of a workbook using a macro that calls another macro

Hello,

I have been trying to run a macro (Macro1) that calls another macro
(Macro2) and runs the latter on all the worksheets of an Excel
workbook. But Macro2 seems to be running on only three worksheets of
the workbook. I am quite sure about the accuracy of Macro2. There is
some problem with the code of Macro1 and I do not quite know where the
problem lies. The code is as follows:

----------------------------------------------------------------------------------------------------------------------
Sub Macro1()
Dim sFile$
'Specifying path of the Excel file
Const path = "E:\TEST\"
Dim WS_Count As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
Dim ws As Worksheet
Dim I As Integer
sFile = Dir(path & "*.xls")
Do While sFile < ""
Workbooks.Open (path & sFile)
Set ws = ActiveSheet
For I = 1 To WS_Count
Set ws = ActiveWorkbook.Worksheets(I)
ws.Activate
Range("A1").Select
Application.Run "Macro2"
Next I
ActiveWorkbook.Close savechanges:=True
sFile = Dir
Exit Do
Loop
End Sub
-----------------------------------------------------------------------------------------------------------------

Please help me out as I need this problem to be sorted out urgently.


Thanks,

Sairam

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Problem in updating all worksheets of a workbook using a macro that calls another macro

Hi Sairam,

Your problem would appear to reside in the fact that WS_Count variable is
defined as the number of worksheets in the workbook which is active when the
code starts, not the workbook which is opened. If therefore, the currently
active workbook only contains three worksheets, only the first three
worksheets in any workbook which is opened will be processed by your code.

To resolve this, move the line:

WS_Count = ActiveWorkbook.Worksheets.Count


after the lne:

Workbooks.Open (path & sFile)



---
Regards,
Norman



wrote in message
oups.com...
Hello,

I have been trying to run a macro (Macro1) that calls another macro
(Macro2) and runs the latter on all the worksheets of an Excel
workbook. But Macro2 seems to be running on only three worksheets of
the workbook. I am quite sure about the accuracy of Macro2. There is
some problem with the code of Macro1 and I do not quite know where the
problem lies. The code is as follows:

----------------------------------------------------------------------------------------------------------------------
Sub Macro1()
Dim sFile$
'Specifying path of the Excel file
Const path = "E:\TEST\"
Dim WS_Count As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
Dim ws As Worksheet
Dim I As Integer
sFile = Dir(path & "*.xls")
Do While sFile < ""
Workbooks.Open (path & sFile)
Set ws = ActiveSheet
For I = 1 To WS_Count
Set ws = ActiveWorkbook.Worksheets(I)
ws.Activate
Range("A1").Select
Application.Run "Macro2"
Next I
ActiveWorkbook.Close savechanges:=True
sFile = Dir
Exit Do
Loop
End Sub
-----------------------------------------------------------------------------------------------------------------

Please help me out as I need this problem to be sorted out urgently.


Thanks,

Sairam



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem in updating all worksheets of a workbook using a macro that calls another macro

Thanks a lot, Norman.

Your solution has worked out perfectly.



Regards,

Sairam

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem in updating all worksheets of a workbook using a macro that calls another macro

Thanks a lot, Norman.

Your solution has worked out perfectly.



Regards,

Sairam

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
Macro for updating a new template for a workbook Gunner Excel Discussion (Misc queries) 0 April 11th 09 10:39 AM
Updating copy of Macro workbook... have_a_cup Excel Discussion (Misc queries) 2 June 29th 06 03:13 PM
Macro Formula Updating Problem Tim Excel Programming 0 June 8th 04 05:16 PM
one macro calls the other ebony Excel Programming 1 January 7th 04 05:27 AM
Macro Calls lchhat Excel Programming 5 November 14th 03 03:56 PM


All times are GMT +1. The time now is 11:19 AM.

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"