Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-06-2011, 06:11 PM
judicial85 judicial85 is offline Optional File Browsing Windows 7 Optional File Browsing Office 2010 (Version 14.0)
Advanced Beginner
Optional File Browsing
 
Join Date: Nov 2010
Posts: 64
judicial85 is on a distinguished road
Default Optional File Browsing

Hello!



I currently have a macro that automatically imports "DATA.txt" off of the Desktop and into EXCEL. What I was thinking of was to add a subroutine that if "DATA.txt" was not found by the program, it would open a file browsing window so the user can select the file themselves.

Can someone help with that?
Thanks, Bryan

(Current code piece)
Code:
'IMPORT the file from desktop (DATA.txt)
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\BK\Desktop\DATA.txt", Destination:=Range("$A$1"))
        .name = "dos"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .TextFileFixedColumnWidths = Array(13, 12)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
Reply With Quote
  #2  
Old 03-08-2011, 01:10 AM
macropod's Avatar
macropod macropod is offline Optional File Browsing Windows 7 32bit Optional File Browsing Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Here's one way:
Code:
Dim strFile As String
strFile = "C:\Users\BK\Desktop\DATA.txt"
With Application.FileDialog(msoFileDialogFilePicker)
  .AllowMultiSelect = False
  .Show
  If .SelectedItems.Count = 1 Then
    strFile = .SelectedItems(1)
  Else
    MsgBox "No file selected", vbExclamation
    Exit Sub
  End If
End If
'IMPORT the file from desktop (DATA.txt)
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & strFile, Destination:=Range("$A$1"))
     ...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
browser window, ease-of-use, import

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Find text in doc file & copy to another file northstarman Word 1 11-05-2010 08:15 AM
Optional File Browsing Word Macro: Save file as text with current file name jabberwocky12 Word VBA 2 10-22-2010 12:23 PM
linking a word file and an excell file on a macbook pro Fleur Office 0 07-14-2010 08:19 PM
Optional File Browsing How to open ppt file directly with slide show when clicked on file. praveen_p PowerPoint 1 05-06-2009 12:42 PM
Outlook xp slow when Browsing to attached a file jmelgar1 Outlook 0 09-23-2008 01:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft