Change connection source path/filename

DannyPt

New Member
Joined
Dec 30, 2016
Messages
2
Hi guys,

I am trying to create a macro that change the connection direction after searching for a file that starts with "filename", for example, and the xtension for it is .xlsx and also the path will change because it goes into the C:\Users"username"\SharePoint\ folder and the username is always changing, since this is for more than one person.

I have tryed something like this:

Code:
Private Sub FileSearch()
Dim qPath As String

qPath = Environ("Sharepoint") & "Folder\Subfolder\filename" & "*.xlsx"
'strPath = Application.GetOpenFilename(Title:=qPath, FileFilter:=".xlsx")
ActiveWorkbook.Connections.Item(1).OLEDBConnection.SourceConnectionFile = qPath

End Sub

It gives me no error, but i know that it isn't updating the connection because i tryed to change the file to filename1.xlsx and the connection is still going to filename.xlsx

I don't know if i am beeing cleary here because i know that is a little bit confuse.

Thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

DannyPt

New Member
Joined
Dec 30, 2016
Messages
2
I tryed to edit this post so i could do a little update but i dodnt found the "Edit" option

I noticed that the previous code would change the "Connection File" on the Connection Properties, but in the "Connection string" there isstill the previous file.

Also, the file that appear in the "Connection File" ont he Connection Properties it is "Folder\Subfolder\filename*.xlsx", so i would say that it is doing a simple print of the file to the connection file but, since that file doesn't exist, it doesn't change the Connection String to the one i want.

So, for the folder issue, i used the ThisWoorkbook.Path and then add the subfolder, since the woorkbook is in the main folder
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Edit is limited by length of time on the site, and then on 10 mins max.
 
Upvote 0

Forum statistics

Threads
1,191,165
Messages
5,985,033
Members
439,935
Latest member
Monty238

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top