Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Exit Macro if<vbYes

I have this code and it works good. But how can i get it to exit the macro if
< vbyes

Thanks Mike

Set FD = Application.FileDialog(msoFileDialogOpen)
With Application.FileDialog(msoFileDialogOpen)

If .Show Then .Execute

End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Exit Macro if<vbYes

I take it that you mean if the user cancels instead of actually selecting a
file.
The following is straight out of VBA help for Excel 2007 and might help.
Note that it does not open the file, you need to do that with a separate
open statement.

Sub Test_File_Select()

Dim fd As FileDialog
Dim vrtSelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogOpen)

With fd

'Limit user to select single file.
'Note use Ctrl key to multiselect if true

.AllowMultiSelect = False

'Use the Show method to display the File Picker _
'dialog box and return the user's action.
'If the user presses the button...

If .Show = -1 Then

'Step through each string in the _
'FileDialogSelectedItems collection.

For Each vrtSelectedItem In .SelectedItems

'vrtSelectedItem is aString that contains _
'the path of each selected item.
'You can use any file I/O functions that _
'you want to work with this path.
'This example displays the path in a _
message box.

MsgBox "Selected item's path: " & vrtSelectedItem

Next

Else
MsgBox "User pressed cancel"
End If
End With


End Sub

"Mike" wrote:

I have this code and it works good. But how can i get it to exit the macro if
< vbyes

Thanks Mike

Set FD = Application.FileDialog(msoFileDialogOpen)
With Application.FileDialog(msoFileDialogOpen)

If .Show Then .Execute

End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Exit Macro if<vbYes

With Application.FileDialog(msoFileDialogOpen)

.Show
If .SelectedItems.Count = 0 Then
Exit Sub
End If

End With


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mike" wrote in message
...
I have this code and it works good. But how can i get it to exit the macro
if
< vbyes

Thanks Mike

Set FD = Application.FileDialog(msoFileDialogOpen)
With Application.FileDialog(msoFileDialogOpen)

If .Show Then .Execute

End With



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Exit Macro if<vbYes

Not sure if you will need this or if you already know it but just in case to
save you from further problems.

If you use Bob Phillips' method then use the following to open the file if
selected:-

Workbooks.Open Filename:=.SelectedItems(1)

If you use the method I gave you then it is as follows:-

Workbooks.Open Filename:=vrtSelectedItem

Regards,

OssieMac


"Bob Phillips" wrote:

With Application.FileDialog(msoFileDialogOpen)

.Show
If .SelectedItems.Count = 0 Then
Exit Sub
End If

End With


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mike" wrote in message
...
I have this code and it works good. But how can i get it to exit the macro
if
< vbyes

Thanks Mike

Set FD = Application.FileDialog(msoFileDialogOpen)
With Application.FileDialog(msoFileDialogOpen)

If .Show Then .Execute

End With




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run a macro on exit More Macro Help Needed Excel Programming 3 January 11th 10 11:34 PM
Run macro on exit Steve Excel Discussion (Misc queries) 12 October 25th 09 01:43 PM
MsgBox, VBYes, VBNo Richard Excel Programming 2 February 18th 06 05:28 PM
on exit macro ditchy Excel Discussion (Misc queries) 2 May 3rd 05 12:11 AM
If vbYes Then help... RPIJG[_21_] Excel Programming 6 May 17th 04 05:33 PM


All times are GMT +1. The time now is 07:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"