Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I created a macro that imports a file into Excel 2007 and with Bob Phillips
help was able to extract the file name from the path. The code works fine on my computer (I have VB6 installed), but when other users run the macro they get an object library error (they do not have VB6 installed). Is there a way to modify the Function GetFileName so that it will work using Excel VBA code? Below is the code so far. any and all suggestions are greatly welcomed. Dim myFileName As Variant Sub ImportRunData() 1 ImportDisplayRDFile 2 If myFileName < False Then GetFileName (myFileName) End Sub Sub ImportDisplayRDFile() ' 'ImportRunDataFile Macro ' 'This macro will import and display a DSS Furnace RD file in Excel ' 'THIS SECTION ALLOWS THE USER TO NAVIGATE TO THE FILE LOCATION AND IMPORT IT CORRECTLY 1 myFileName = Application.GetOpenFilename(FileFilter:="Text Files, *.csv") 2 If myFileName = False Then 3 Exit Sub 'user hit cancle 4 End If 5 Sheets("Sheet1").Select 6 With ActiveSheet 7 With .QueryTables.Add(Connection:="Text;" & myFileName, Destination:=.Range("$AG$1")) 8 .Name = "Pick Place for JRB001078B DDU" 9 .FieldNames = True 10 .RowNumbers = False 11 .FillAdjacentFormulas = False 12 .PreserveFormatting = True 13 .RefreshOnFileOpen = False 14 .RefreshStyle = xlInsertDeleteCells 15 .SavePassword = False 16 .SaveData = True 17 .AdjustColumnWidth = True 18 .RefreshPeriod = 0 19 .TextFilePromptOnRefresh = False 20 .TextFilePlatform = 437 21 .TextFileStartRow = 1 22 .TextFileParseType = xlDelimited 23 .TextFileTextQualifier = xlTextQualifierDoubleQuote 24 .TextFileConsecutiveDelimiter = False 25 .TextFileTabDelimiter = True 26 .TextFileSemicolonDelimiter = False 27 .TextFileCommaDelimiter = True 28 .TextFileSpaceDelimiter = False 29 .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _ , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) 30 .TextFileTrailingMinusNumbers = True 31 .Refresh BackgroundQuery:=False 32 End With 33 Application.ScreenUpdating = False 34 Sheets("Sheet1").Select 35 Range("P7").Select 36 Selection.NumberFormat = "[h]:mm" 37 Range("G9").Select 38 Selection.NumberFormat = "[h]:mm" 39 Range("L9").Select 40 Selection.NumberFormat = "[h]:mm" 41 Range("Q9").Select 42 Selection.NumberFormat = "[h]:mm" 43 Range("V9").Select 44 Selection.NumberFormat = "[h]:mm" 45 Range("V13").Select 46 Selection.NumberFormat = "[h]:mm" 47 Range("AA9").Select 48 Selection.NumberFormat = "[h]:mm" 49 Range("AG1:DM4200").Select 50 Selection.Copy 51 Sheets("RUN DATA FILE").Select 52 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False 53 Application.CutCopyMode = False 54 Range("A1").Select 55 Sheets("Sheet1").Select 56 Range("B1").Select 57 End With End Sub Function GetFileName(stFullName As String) As String GetFileName = Right$(stFullName, Len(stFullName) - InStrRev(stFullName, Application.PathSeparator)) Range("F5") = GetFileName End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Formula too long - new file path is shorter than old file path - Excel 2003 | Excel Worksheet Functions | |||
Path/File access error | Excel Programming | |||
Run-time error 75 Path/File access error | Excel Programming | |||
Path/File access error (Error 75) using Name Statement | Excel Programming | |||
Path/File access error (Error 75) after using Name Statement | Excel Programming |