Relative Paths within Excel for CSV imports -


i'm hoping can done i've been finding far excel not support relative paths workbook connections. have here excel workbook auto-updates worksheets csv files. these pull in data hard coded folder (c:\temp\premiumreports\name_of_csv_file.csv). method forces me put c:\temp\premiumreports everytime or if send file customer have create same directory structure. place xlsx file folder (c:\report or user's desktop) necessary csv files , when open xlsx data imported automatically. possible?

current workbook connection

enter image description here thanks!

if work book file located in same folder csv file can utilize activeworkbook.path method set relative path.

example assuming csv file name , connection name same:

sub refreshmsgconnection()     dim csvfilename string     csvfilename = "msg_by_weeks.csv"      dim filepath string     filepath = activeworkbook.path      dim constring string     constring = "text;" & filepath & "\" & csvfilename      activeworkbook.connections("msg_by_weeks").ranges.item(1).querytable         .connection = constring         .textfileplatform = 437         .textfilestartrow = 1         .textfileparsetype = xldelimited         .textfiletextqualifier = xltextqualifierdoublequote         .textfileconsecutivedelimiter = false         .textfiletabdelimiter = false         .textfilesemicolondelimiter = false         .textfilecommadelimiter = true         .textfilespacedelimiter = false         .textfilecolumndatatypes = array(1, 1, 1, 1)         .textfiletrailingminusnumbers = true         .textfilepromptonrefresh = false         .refresh backgroundquery:=false     end end sub 

you may have play of settings based on configuration such delimiters etc. if you're having trouble, record macro while setup new connection desired format , copy settings in sub.

if file not found, pop file selection box user locate desired file.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -