View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Need to make sure workbook is open before proceeding

Dim Doc2Wkbk as workbook

set doc2wkbk = nothing
on error resume next
set doc2wkbk = workbooks("doc2.xls") 'no drive and no path
on error goto 0

if doc2wkbk is nothing then
msgbox "It's not open"
exit sub
end if

=========
Maybe you could have your code just open it (if you know where it is):

if doc2wkbk is nothing then
on error resume next
'include drive and path on the next line
set doc2wkbk = workbooks.open(filename:="c:\path\doc2.xls")
on error goto 0

if doc2wkbk is nothing then
msgbox "it's not open and I don't know where it is!
exit sub '????
else
msgbox "it was opened, but now it is!"
end if
end if



Munchkin wrote:

Can you help - Users of my form need to make sure Doc2 is open before running
the macro. If Doc2 is not open I need the macro to stop and a message box to
pop up stating Doc2 is not open.

Application.WindowState = xlMinimized


Range("H2").Select
Selection.Copy


Range("E1").Select
ActiveSheet.Paste


--

Dave Peterson