#1   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.misc
Otto Moehrbach
 
Posts: n/a
Default 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



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 Help In Excel welshlad Excel Discussion (Misc queries) 14 October 26th 05 02:34 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Macro to close excel okanem Excel Discussion (Misc queries) 1 July 19th 05 10:01 AM
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM
Excel macro that opens new MS Word file and pastes data as a pictu Rob Excel Worksheet Functions 0 July 6th 05 05:12 PM


All times are GMT +1. The time now is 11:03 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"