ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Setting up and Configuration of Excel (https://www.excelbanter.com/setting-up-configuration-excel/)
-   -   Help:Running a macro in one excel workbook from another workbook (https://www.excelbanter.com/setting-up-configuration-excel/63926-help-running-macro-one-excel-workbook-another-workbook.html)

R Kapoor

Help:Running a macro in one excel workbook from another workbook
 
I am trying to execute the following given macro from the current workbook.
The macro opens the workbook "2148.xls" and waits there. It does not proceed
to run the macro "NextDay" as given in line number 3.

However, if I execute the entire macro step by step from Visual Basic (using
F8) it works fine. What could be the problem? What is the solution.



Workbooks.Open Filename:="C:\Data\GLIF\2148.xls"
Windows("2148.xls").Activate
Application.Run "2148.xls!NextDay"
Sheets("2148").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$51"
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
Sheets("Summary").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
ActiveWorkbook.Save
ActiveWorkbook.Close



Bob Phillips

Help:Running a macro in one excel workbook from another workbook
 
A simple test for me worked fine. Is there anything in the NextDay macro
that might be causing it to fail?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"R Kapoor" wrote in message
...
I am trying to execute the following given macro from the current

workbook.
The macro opens the workbook "2148.xls" and waits there. It does not

proceed
to run the macro "NextDay" as given in line number 3.

However, if I execute the entire macro step by step from Visual Basic

(using
F8) it works fine. What could be the problem? What is the solution.



Workbooks.Open Filename:="C:\Data\GLIF\2148.xls"
Windows("2148.xls").Activate
Application.Run "2148.xls!NextDay"
Sheets("2148").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$51"
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
Sheets("Summary").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
ActiveWorkbook.Save
ActiveWorkbook.Close





R Kapoor

Help:Running a macro in one excel workbook from another workbo
 
Bob,

NextDay macro is as under:

Sub NextDay()

Sheets("Summary").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields ("Zone").AutoSort _
xlAscending, "Zone"

Columns("H:H").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Range("C6:C45").Select
Range("C45").Activate
Selection.Copy
Range("H6").Select
ActiveSheet.Paste

Sheets("2148").Select
Columns("h:h").Select
Selection.Insert Shift:=xlToRight
Columns("e:e").Select
Selection.Copy
Columns("h:h").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save

End Sub


"Bob Phillips" wrote:

A simple test for me worked fine. Is there anything in the NextDay macro
that might be causing it to fail?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"R Kapoor" wrote in message
...
I am trying to execute the following given macro from the current

workbook.
The macro opens the workbook "2148.xls" and waits there. It does not

proceed
to run the macro "NextDay" as given in line number 3.

However, if I execute the entire macro step by step from Visual Basic

(using
F8) it works fine. What could be the problem? What is the solution.



Workbooks.Open Filename:="C:\Data\GLIF\2148.xls"
Windows("2148.xls").Activate
Application.Run "2148.xls!NextDay"
Sheets("2148").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$51"
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
Sheets("Summary").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
ActiveWorkbook.Save
ActiveWorkbook.Close






R Kapoor

Help:Running a macro in one excel workbook from another workbo
 
The following may help :

When I run the macro from the present worksheet, it opens the other workbook
and waits i.e. it does not execute the macro 'NextDay'. But on the otherhand
it runs perfectly under debug mode when I execute the macros - step-by-step.
Any hint on solving this problem?



"R Kapoor" wrote:

Bob,

NextDay macro is as under:

Sub NextDay()

Sheets("Summary").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields ("Zone").AutoSort _
xlAscending, "Zone"

Columns("H:H").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Range("C6:C45").Select
Range("C45").Activate
Selection.Copy
Range("H6").Select
ActiveSheet.Paste

Sheets("2148").Select
Columns("h:h").Select
Selection.Insert Shift:=xlToRight
Columns("e:e").Select
Selection.Copy
Columns("h:h").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save

End Sub


"Bob Phillips" wrote:

A simple test for me worked fine. Is there anything in the NextDay macro
that might be causing it to fail?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"R Kapoor" wrote in message
...
I am trying to execute the following given macro from the current

workbook.
The macro opens the workbook "2148.xls" and waits there. It does not

proceed
to run the macro "NextDay" as given in line number 3.

However, if I execute the entire macro step by step from Visual Basic

(using
F8) it works fine. What could be the problem? What is the solution.



Workbooks.Open Filename:="C:\Data\GLIF\2148.xls"
Windows("2148.xls").Activate
Application.Run "2148.xls!NextDay"
Sheets("2148").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$51"
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
Sheets("Summary").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
ActiveWorkbook.Save
ActiveWorkbook.Close







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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com