Hello,
I'm working on a macro to try and refresh a pivot table by clearing out the data table and importing a .txt file but I want a browser window to allow me to choose the file that I want to import. Any suggestions?
Thanks again.
Hello,
I'm working on a macro to try and refresh a pivot table by clearing out the data table and importing a .txt file but I want a browser window to allow me to choose the file that I want to import. Any suggestions?
Thanks again.
Found a solution that seems to work
![]()
Option Explicit Sub Macro1() ' ' Macro1 Macro ' ' Dim fName As String fName = Application.GetOpenFilename("Text Files (*.txt), *.txt") If fName = "False" Then Exit Sub ' Sheets("msp_fee").Select Cells.Select Selection.QueryTable.Delete Selection.ClearContents With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fName, _ Destination:=Range("$A$1")) .Name = "msp_fee" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 437 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileOtherDelimiter = "|" .TextFileColumnDataTypes = Array(1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With Rows("1:7").Select Selection.Delete Shift:=xlUp Sheets("Sheet1").Select Range("A5").Select ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks