Programmatic indication of file to be PROCESSED.
Morning Hari (it is here ;-))
I would check if it is open, then proceed, else offer the dialog
If Not IsOpen("myWorkbook.xls") Then
'do the GetFileOPen
'and open it
End If
'rest of code
Function IsOpen(FileName As String) As Boolean
On Error Resume Next
IsOpen = CBool(Len(Workbooks(FileName).Name))
End Function
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Hari Prasadh" wrote in message
...
Hi,
I want user to have the ability to choose a workbook for processing. Now
there are 2 possibilities.
a) Workbook is not open in the present excel session - In that case I can
use GetOpenFileName method for opening the desired file and continue with
Macro operation.
b) Workbook is ALREADY open in the present excel session - In that case
how
to offer the user the facility of indicating that so and so workbook which
is already open should be used for continuing the macro operation.
And how to interweave the above 2 methods. I thought of the following
which
am pasting here. If there is a more efficient method please tell me. (Also
in my code the, macro goes in to debug mode if user writes nothing in the
input box but presses a ok. How to take care of that? Also is there
anything
else I should be wary of while doing this?) Please guide me.
Option Explicit
Sub FiletobeProcessed()
Dim i As Byte
Dim p As String
i = 0
Do
i = Application.InputBox("If the file to be UPCODED is not open then
write 1 else write 2", "File open or not?")
If i = 1 Then
p = Application.GetOpenFilename("XLS files (*.xls),*.xls")
Workbooks.Open (p)
ElseIf i = 2 Then
' code for condition b). I dont know how to put this code. I would
like
to get the _
name of the file which is already open so that I can integrate it
with
other Macros. _
A standard Input Box might not work as user might make a Typo in
writing the name _
of the file and another its difficult to write long file names.
End If
Loop While Not (i = 1 Or i = 2)
End Sub
Thanks a lot,
Hari
India
|