+ Reply to Thread
Results 1 to 3 of 3

Button choose a file and open. If person clicks cancel Excel still opens it.

  1. #1
    Registered User
    Join Date
    09-12-2014
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    10

    Button choose a file and open. If person clicks cancel Excel still opens it.

    I have a very simple macro.
    User can choose a file (click a button for example if I add this macro to a button) then if clicks ok then the file name will be added to field E6 (I will need it later for other macros) and the file will be opened.
    My problem is if the user choose Cancel then the file which name is in E6 already will be opened. How can I avoid this?

    Sub VChoose_folder()
    v = "nothing"
    With Application.FileDialog(msoFileDialogFilePicker)
    .Title = "Choose file"
    .AllowMultiSelect = False
    .InitialFileName = CurDir
    If .Show = -1 Then v = .SelectedItems(1)
    End With
    If v <> "nothing" Then
    Range("E6").Value = v
    End If
    Workbooks.Open Filename:=Range("E6")

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Button choose a file and open. If person clicks cancel Excel still opens it.

    if v<>"FALSE" i think

    also you need to move the workbook.open into the if block
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    09-12-2014
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    10

    Re: Button choose a file and open. If person clicks cancel Excel still opens it.

    Thank you so much, I added the workbooks.open into the if block and now it works correctly. Thanks a lot

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. When I open a workbook, how can I choose which worksheet opens?
    By josephdmcc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2006, 12:10 PM
  2. [SOLVED] Open an Outlook folder when a user clicks on a command button ...
    By Rob Keel in forum Excel General
    Replies: 2
    Last Post: 08-01-2005, 04:05 AM
  3. [SOLVED] Open an Outlook folder when a user clicks on a command button ...
    By Rob Keel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2005, 04:05 AM
  4. [SOLVED] Cancel Button in Open File Window
    By SS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2005, 02:37 PM
  5. [SOLVED] unable to open Excel file by double clicks
    By Renyan in forum Excel General
    Replies: 2
    Last Post: 01-15-2005, 10:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1