ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   GetOpenFilename Close (https://www.excelbanter.com/excel-programming/407753-getopenfilename-close.html)

Karen53

GetOpenFilename Close
 
Hi,

How do I catch it if the user closes the GetOpenFilename window with the
titlebar 'X' so my code doesn't error out?


--
Thanks for your help.
Karen53

Karen53

GetOpenFilename Close
 
Hi,

To clarify, if they click the 'X' or cancel, how can I identify this so my
code stops running?

Sub wkbookCreate()

Dim wbkCopyFrom As Workbook
Dim rngCopyFrom As Range
Dim rngCopyTo As Range
Dim FromwbkName As String
Dim FromPath As String
Dim FromwbkPath As String

FromwbkPath = Application.GetOpenFilename

Call GetNamePath(FromwbkName, FromPath, FromwbkPath)

On Error Resume Next

Set wbkCopyFrom = Workbooks(FromwbkPath)
If wbkCopyFrom Is Nothing Then
Set wbkCopyFrom = Workbooks.Open(FromwbkPath)
On Error GoTo 0
If wbkCopyFrom Is Nothing Then
MsgBox "Cannot find originating file"
Else
Application.ScreenUpdating = False

ThisWorkbook.Sheets((Replace(Tablespg.Name, "'",
"''"))).Unprotect Password:=([MyPassword])

'Pool lists
'CAM
Set rngCopyFrom = wbkCopyFrom.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("J4:J21")
Set rngCopyTo = ThisWorkbook.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("J4:J21")
rngCopyTo.Value = rngCopyFrom.Value

'Tax
Set rngCopyFrom = wbkCopyFrom.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("M4:M21")
Set rngCopyTo = ThisWorkbook.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("M4:M21")
rngCopyTo.Value = rngCopyFrom.Value

ThisWorkbook.Sheets(Replace(Tablespg.Name, "'", "''")).Protect
Password:=([MyPassword])

End If
End If

ActiveWorkbook.SaveAs Filename:=FromPath & FromwbkName & " Final.xls"

Application.ScreenUpdating = True

End Sub



--
Thanks for your help.
Karen53


"Karen53" wrote:

Hi,

How do I catch it if the user closes the GetOpenFilename window with the
titlebar 'X' so my code doesn't error out?


--
Thanks for your help.
Karen53


Karen53

GetOpenFilename Close
 
Never Mind. I've got this one. Thx
--
Thanks for your help.
Karen53


"Karen53" wrote:

Hi,

To clarify, if they click the 'X' or cancel, how can I identify this so my
code stops running?

Sub wkbookCreate()

Dim wbkCopyFrom As Workbook
Dim rngCopyFrom As Range
Dim rngCopyTo As Range
Dim FromwbkName As String
Dim FromPath As String
Dim FromwbkPath As String

FromwbkPath = Application.GetOpenFilename

Call GetNamePath(FromwbkName, FromPath, FromwbkPath)

On Error Resume Next

Set wbkCopyFrom = Workbooks(FromwbkPath)
If wbkCopyFrom Is Nothing Then
Set wbkCopyFrom = Workbooks.Open(FromwbkPath)
On Error GoTo 0
If wbkCopyFrom Is Nothing Then
MsgBox "Cannot find originating file"
Else
Application.ScreenUpdating = False

ThisWorkbook.Sheets((Replace(Tablespg.Name, "'",
"''"))).Unprotect Password:=([MyPassword])

'Pool lists
'CAM
Set rngCopyFrom = wbkCopyFrom.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("J4:J21")
Set rngCopyTo = ThisWorkbook.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("J4:J21")
rngCopyTo.Value = rngCopyFrom.Value

'Tax
Set rngCopyFrom = wbkCopyFrom.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("M4:M21")
Set rngCopyTo = ThisWorkbook.Sheets(Replace(Tablespg.Name, "'",
"''")).Range("M4:M21")
rngCopyTo.Value = rngCopyFrom.Value

ThisWorkbook.Sheets(Replace(Tablespg.Name, "'", "''")).Protect
Password:=([MyPassword])

End If
End If

ActiveWorkbook.SaveAs Filename:=FromPath & FromwbkName & " Final.xls"

Application.ScreenUpdating = True

End Sub



--
Thanks for your help.
Karen53


"Karen53" wrote:

Hi,

How do I catch it if the user closes the GetOpenFilename window with the
titlebar 'X' so my code doesn't error out?


--
Thanks for your help.
Karen53



All times are GMT +1. The time now is 04:10 AM.

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