Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2019, 06:05 PM
MrKim MrKim is offline Changing Absolute path to Relative in a Macro Windows 10 Changing Absolute path to Relative in a Macro Office 2019
Novice
Changing Absolute path to Relative in a Macro
 
Join Date: Jan 2019
Posts: 8
MrKim is on a distinguished road
Default


Views: 10 Size: 35.7 KB">Data Import Test ver25thJan2019.xlsm


x.xls

Still having grief.
Below is the path-modified code.
I'm attaching test file.
The 'x' csv test data is also attached as an excel file as I can't upload a .csv file here, so that will need to be renamed.




Code:
Sub DataImportTest25th_1()
'
' DataImportTest25th_1 Macro
'

'
    Application.CutCopyMode = False
    ActiveWorkbook.Queries.Add Name:="x", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Source = Csv.Document(File.Contents(ActiveWorkbook.Path & ""\x.csv""),[Delimiter="","", Columns=10, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & "    #""Promoted Headers"" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(#""Promoted " & _
        "Headers"",{{""Lot_No"", Int64.Type}, {""Unit"", type text}, {""Cont_UE"", Int64.Type}, {""Int_UE"", Int64.Type}, {""Owners_Name"", type text}, {""Owners_Address"", type text}, {""Owners_Phone"", type text}, {""Owners_Email"", type text}, {""Committee_Member"", type text}, {""Balance"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Changed Type"""
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=x;Extended Properties=""""" _
        , Destination:=Range("$B$8")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [x]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "x"
        .Refresh BackgroundQuery:=False
    End With
    ActiveWindow.SmallScroll Down:=-3
    Application.CommandBars("Queries and Connections").Visible = False
    ActiveWorkbook.Save
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Absolute path to Relative in a Macro Relative path for hyperlinks wpryan Word 4 01-09-2019 05:15 PM
Changing Absolute path to Relative in a Macro Image absolute position relative to page thuizt Word VBA 4 08-01-2017 07:25 AM
Hyperlinks defaulting to absolute instead of relative!!! wdzambotti Word VBA 1 08-17-2015 09:03 PM
Changing Absolute path to Relative in a Macro PowerPoint VBA: ApplyTemplate & absolute path tinfanide PowerPoint 2 04-05-2013 07:28 AM
Changing Absolute path to Relative in a Macro Relative path to desktop b0x4it Word VBA 4 05-18-2011 11:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:22 PM.


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