ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File Loading Problems (https://www.excelbanter.com/excel-programming/302814-file-loading-problems.html)

Jason Hancock

File Loading Problems
 
Okay, here is the problem. The code below crashes out at the
Windows(UFFN).Activate part. I think that the code is assigning False
to the UF instead of assigning the input from the selection window. Is
there some other way to make sure that the then statement runs when the
click Cancel.

While I'm thinking about it, is there some way to make sure the write
restriction password dialog box doesn't appear?

Dim UF As Variant
Dim UFFN As Variant
UF = Application.GetOpenFilename(Title:="This Weeks Projections for
Angie")
If UF < False Then

Workbooks.Open Filename:=UF

Set wbUF = Workbooks.Open(Filename:=UF,
WriteResPassword:="sue")
UFFN = wbUF.Name

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

Else

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


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

Dave Peterson[_3_]

File Loading Problems
 
I think I'd stop using the Windows collection.

Maybe something like:

Option Explicit
Sub testme02()

Dim UF As Variant
Dim wbUF As Workbook

UF = Application.GetOpenFilename(Title:="This Weeks Projections for Angie")
If UF < False Then
Set wbUF = Workbooks.Open(Filename:=UF, WriteResPassword:="sue")

wbUF.Sheets("angie").Copy _
after:=Workbooks("Projection summary.xls").Sheets("summary")
'or after:=thisworkbook.sheets("summary")

wbUF.Close savechanges:=False
Else
MsgBox "No projection forms selected for Angie. You must" _
& " add them manually later."
End If
End Sub

Untested, but it compiled ok.

Jason Hancock wrote:

Okay, here is the problem. The code below crashes out at the
Windows(UFFN).Activate part. I think that the code is assigning False
to the UF instead of assigning the input from the selection window. Is
there some other way to make sure that the then statement runs when the
click Cancel.

While I'm thinking about it, is there some way to make sure the write
restriction password dialog box doesn't appear?

Dim UF As Variant
Dim UFFN As Variant
UF = Application.GetOpenFilename(Title:="This Weeks Projections for
Angie")
If UF < False Then

Workbooks.Open Filename:=UF

Set wbUF = Workbooks.Open(Filename:=UF,
WriteResPassword:="sue")
UFFN = wbUF.Name

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

Else

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

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


--

Dave Peterson



All times are GMT +1. The time now is 11:37 PM.

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