+ Reply to Thread
Results 1 to 2 of 2

Can someone fix this code? Trying to create vba code that will prompt opening any file

  1. #1
    Registered User
    Join Date
    01-11-2020
    Location
    USA
    MS-Off Ver
    2010
    Posts
    4

    Lightbulb Can someone fix this code? Trying to create vba code that will prompt opening any file

    Sub CarryOverData()

    Dim FName As String
    Dim wkBook As Workbook

    With Application
    .ScreenUpdating = False
    FName = .GetOpenFilename
    End With

    If FName <> "False" Then
    Set wkBook = Workbooks.Open( _
    Filename:=FName)

    With wkBook
    .Worksheets("Sheet1").Range("A:Z").Copy _
    Destination:=ThisWorkbook.Worksheets("Sheet1").Range("A:Z")

    .Close _
    SaveChanges:=False
    End With
    End If

    With Application
    .CutCopyMode = False
    .ScreenUpdating = True
    End With

    End Sub

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Can someone fix this code? Trying to create vba code that will prompt opening any fil

    well what's wrong with the code? what is the error message you're getting. you have a couple of options I think. you can use the windows SHELL() to open files with their default programs. or you can use GETOPENFILNAME() like you are doing. for SHELL, you would do this:
    Please Login or Register  to view this content.
    you can also use the FILE SYSTEM OBJECT for IN/OUT operations like data streaming (e.g. - byte-by-byte reading). you can read about that here: https://docs.microsoft.com/en-us/off...mobject-object

+ 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. [SOLVED] Auto save as VBA code causes Debugger prompt if I don't want to replace file
    By Stryfe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2018, 09:30 AM
  2. [SOLVED] VB code to check if file exit before opening excel file.
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-24-2017, 06:17 PM
  3. Replies: 1
    Last Post: 06-20-2017, 10:28 AM
  4. code for opening a file
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2015, 07:10 PM
  5. [SOLVED] VBA code for opening a file with a variable version number in the file name
    By trishcollins in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-04-2014, 04:38 PM
  6. Code to Prompt for File then Convert to PDF
    By sunmasque1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-29-2013, 03:39 PM
  7. [SOLVED] Error in code - play music file automatically after opening file
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-15-2013, 10:06 AM

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