Consulting

Results 1 to 7 of 7

Thread: fixing show message when open workbook from dialog to copy data

  1. #1

    fixing show message when open workbook from dialog to copy data

    hello
    this is my code doesn't work very well i no know it works until this line
    HTML Code:
    1 MsgBox "name of  the  file  is not correct", vbCritical
    i'm sure about the name of opened file it supposes open the file and copy data but the code open the file but not copy data because show the message
    i hope some body help

    HTML Code:
    Sub Test()
    Dim file_name As Variant
    Dim open_wk As Workbook
    On Error GoTo 1
    file_name = Application.GetOpenFilename(Title:="choose the file ", FileFilter:="Excel Files *.xlsx (*.xlsx),")
    If file_name = False Then1 MsgBox "name of  the  file  is not correct", vbCritical
    Exit Sub
    Else
    Set open_wk = Workbooks.Open(file_name)
    EndIf
    Windows("TT1.xlsx").Activate
    Sheets("sheet1").Select
    Range("a2:E15").Select
    Selection.CopyThisWorkbook.Activate
    Sheets("sheet1").Select
    Range("b2").Select
    Selection.PasteSpecial Paste:=xlPasteValues
    ThisWorkbook.Close
    Application.CutCopyMode = False
    End Sub
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Get rid of 'Then1' and make it just 'Then'

    If file_name = False Then1 MsgBox "name of  the  file  is not correct", vbCritical
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    it gives me error in this line
    On Error GoTo 1 i delete 1 also gives error

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I don't think you need the GoTo


    Option Explicit
    
    
    Sub Test()
        Dim file_name As Variant
        Dim open_wk As Workbook
    
    
        file_name = Application.GetOpenFilename(Title:="choose the file ", FileFilter:="Excel Files *.xlsx (*.xlsx),")
        If file_name = False Then
            MsgBox "name of  the  file  is not correct", vbCritical
            Exit Sub
        Else
            Set open_wk = Workbooks.Open(file_name)
        End If
    
    
        Windows("touati1.xlsx").Activate
        Sheets("sheet1").Select
        Range("a2:d15").Select
        Selection.Copy
        ThisWorkbook.Activate
        Sheets("sheet1").Select
        Range("b2").Select
        Selection.PasteSpecial Paste:=xlPasteValues
        ThisWorkbook.Close
        
        Application.CutCopyMode = False
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    it gives me error run time 1004

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I could only look to see if it would open a workbook without error


    I'm not a mind reader

    Which line gives you the 1004 error?

    It could be that "touati1.xlsx" doesn't exist, or there is no "Sheet1", or something else
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    the error in this line
    HTML Code:
    Range("a2:d15").Select

Posting Permissions

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