Thread: Excel macro
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default Excel macro

Hi and thanks of the answer

I have solved my problem. There were needed a little bit more, a
function, which I copied from MS's article (ID 151336). The macro is
working correctly now, but...

Every time I run the macro and the base workbook/File is open Excel
asks me that 'if the workbook is opened again I'll lost someting
unsaved'. And I must answer 'YES'. There is no unsaved data in the
workbook, and that's why I'd like to give the answer inside the code.
How and where?

I copy my new code here.

Sub Kaavapoiminta()
'
' Kaavapoiminta Makro
' kukkoha on nauhoittanut makron 24.11.2005.
'
If
IsOpen("\\taskes000001\keto\Petri\Tuotantoalueet\t uotantoalueet.xls")
Then

Workbooks("tuotantoalueet.xls").Sheets("Taul1").Ra nge("tuotantoalueet").
_
AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("Ehdot"), _
CopyToRange:=Range("Poimi"), Unique:=False
Else

Workbooks.Open(Filename:= _

"\\taskes000001\keto\Petri\Tuotantoalueet\tuotanto alueet.xls").RunAutoMacros
_
Which:=xlAutoOpen
ActiveWindow.WindowState = xlMinimized
ActiveWindow.WindowState = xlMaximized

Workbooks("tuotantoalueet.xls").Sheets("Taul1").Ra nge("tuotantoalueet").
_
AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("Ehdot"), _
CopyToRange:=Range("Poimi"), Unique:=False
End If
End Sub
Function IsOpen(Filename As String) As Boolean
Dim wb As Workbook
For Each wb In Application.Workbooks
If UCase(wb.Name) = UCase(Filename) Then
IsOpen = True
Exit Function
End If
Next wb
IsOpen = False
End Function