Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,423
    Thanks
    125
    Thanked 5 Times in 5 Posts

    VBA Cose to change File type (2007)

    I use the following VBA code to refresh data from Pull Directory. When I select this macro, Import text File Appears, Look in Pull appears which it correct. I want the "Files of type" on the botton to be changed using a macro to "all files", because each month the file name will change for eg Volvo.09 to Volvo.10 etc

    Your assistance will be most appreciated

    Regards

    Howard





    Sub Import_Data()
    Range("Import").QueryTable.Refresh BackgroundQuery:=False
    End Sub


    Your assistance in this regard will be most appreciated

    Regards

    Howard

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA Cose to change File type (2007)

    What is "Pull Directory"?

  3. #3
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,423
    Thanks
    125
    Thanked 5 Times in 5 Posts

    Re: VBA Cose to change File type (2007)

    Hi Hans

    Pull Directory is a directory which I created for downloading files

    Regards

    Howard

  4. #4
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,423
    Thanks
    125
    Thanked 5 Times in 5 Posts

    Re: VBA Code to change File type (2007)

    Hi Hans

    See Attached screen Print where I would like VBA Code to change "files of type" to all

    Regards

    Howard
    Attached Files Attached Files

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA Cose to change File type (2007)

    I don't think you can modify the behavior of the Refresh method. You'll have to write a macro to delete the querytable and the corresponding range and recreate it from scratch.
    I'd start by recording a macro, then edit it to add the prompt for the file. It could look like this:

    Dim varFile As Variant
    varFile = Application.GetOpenFilename
    If VarType(varFile) = vbBoolean Then
    MsgBox "No file selected", vbInformation
    Exit Sub
    End If

    With Range("Import")
    .QueryTable.Delete
    .ClearContents
    End With

    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & varFile, _
    Destination:=Range("Import"))
    ...
    ...
    .Refresh BackgroundQuery:=False
    End With

    The code represented by ... above will depend on your situation

  6. #6
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,423
    Thanks
    125
    Thanked 5 Times in 5 Posts

    Re: VBA Cose to change File type (2007)

    Hi Hans

    Thanks for the help

    Much appreciated

    Regards

    Howard

Posting Permissions

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