ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel macro (https://www.excelbanter.com/excel-discussion-misc-queries/59165-excel-macro.html)

[email protected]

Excel macro
 
I have recorded two macroes, put them together and added if-then-else
statement, but there is something wrong. It does not work. Both macroes
work fine separately.

I try to filter data from a base workbook to an active workbook and
make it run automatically every time when the file is opened. Excel
should check if a base file is open and if so run the filter routine.
If that file is not open it should be opened and run filter.

Sub macroname()

If IsFileOpen("\\serverName\path\fileName.xls") Then

Workbooks("fileName.xls").Sheets("Sheet1").Range(" rangeName1"). _
AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("rangeNames"), _
CopyToRange:=Range("rangeName3"), Unique:=False
Else

Workbooks.Open(Filename:= _
"\\serverName\path\fileName.xls").RunAutoMacro s _
Which:=xlAutoOpen
ActiveWindow.WindowState = xlMaximized

Workbooks("tuotantoalueet.xls").Sheets("Sheet1").R ange("trangeName1").
_
AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("rangeName2"), _
CopyToRange:=Range("rangeName3"), Unique:=False
End If
End Sub

It is not difficult or is it? Excel seems to need some function, but my
knowledge about programming excel macroes is rather weak.

Any hints or a piece of code.

Thanks in advange

hk


Otto Moehrbach

Excel macro
 
Post back and cite the error message that you get and what line of code
produced the error. What is "IsFileOpen"? HTH Otto
wrote in message
oups.com...
I have recorded two macroes, put them together and added if-then-else
statement, but there is something wrong. It does not work. Both macroes
work fine separately.

I try to filter data from a base workbook to an active workbook and
make it run automatically every time when the file is opened. Excel
should check if a base file is open and if so run the filter routine.
If that file is not open it should be opened and run filter.

Sub macroname()

If IsFileOpen("\\serverName\path\fileName.xls") Then

Workbooks("fileName.xls").Sheets("Sheet1").Range(" rangeName1"). _
AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("rangeNames"), _
CopyToRange:=Range("rangeName3"), Unique:=False
Else

Workbooks.Open(Filename:= _
"\\serverName\path\fileName.xls").RunAutoMacro s _
Which:=xlAutoOpen
ActiveWindow.WindowState = xlMaximized

Workbooks("tuotantoalueet.xls").Sheets("Sheet1").R ange("trangeName1").
_
AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("rangeName2"), _
CopyToRange:=Range("rangeName3"), Unique:=False
End If
End Sub

It is not difficult or is it? Excel seems to need some function, but my
knowledge about programming excel macroes is rather weak.

Any hints or a piece of code.

Thanks in advange

hk





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

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