ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File Loading Problem (https://www.excelbanter.com/excel-programming/301952-file-loading-problem.html)

Jason Hancock

File Loading Problem
 
I have encountered an issue while trying to load a file using a macro.
I have used the code below, however, it always gives the "If" statement
regardless of whether the user selects a file and clicks open, double
clicks a file, or clicks cancel. I am trying to run the "If" statement
only if they click cancel. Any help would be greatly appreciated.
Thanks.

If UF < "" Then

MsgBox "No projection forms selected for Angie. You must add
them manually later."

Else

Workbooks.Open Filename:=UF

Set wbUF = Workbooks.Open(Filename:=UF)
UFFN = wbUF.Name

Sheets("Angie").Select
Sheets("Angie").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UFFN).Activate
ActiveWindow.Close
Windows("Projection Summary").Activate

End If


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

MSP77079[_12_]

File Loading Problem
 
You are not showing where UF was defined. Initially it is empy, but
suspect that it is preceeded by something like this:

UF = Application.Dialogs(xlDialogOpen).Show

If the user selected the Cancel button or hit the Esc key, then UF wil
be False, not null.

I suggest replacing the current:

If UF < "" then ...

with the following:

If UF < False then ..

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 06:27 AM.

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