473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

using macros to open a file whose path can be varied

1
I apologize if this has been answered before but I'm new to this and still have lots to learn. Here is what I'm trying to do:

I can run a macro that opens a file as long as that path and file is static:

Workbooks.Open Filename:="C:\mydoc\myfile\Data.xlsx", _
UpdateLinks:=3

suppose I have to move this file to a different path: C:\newdoc\newfile\data.xlsx. My macro will not work unless I go in and edit the macro to reflect where the file is now located.

I prefer to somehow have some sort of variable say in an inputs worksheet so that whatever that variable contains the macro can read it and thus automatically can open the file. thus all I need to do is change the variable and not have to edit the macro.

thanks so much
May 12 '17 #1
1 3745
Luuk
1,047 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.     b = Application.FileDialog(msoFileDialogOpen).Show
  2.     If (b <> 0) Then strPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
  3.     MsgBox "Your filename: " + strPath
  4.  
Jun 10 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: haynesc | last post by:
Hi, I'm having a problem where when trying to open a file in write mode, I get an IOError stating no such file or directory. I'm calling an external program which takes an input file and...
0
by: Stephen | last post by:
could someone give me some advise on a problem I have. At present i have a web application which displays pdf files in a web browser using javascript and the window.open method and pointing to a...
1
by: N. Graves | last post by:
Help me please? I'm have users import tables from other Access Database in one of the process needed to use my ADB. To do this the user opens a form with a field for the file directory and...
3
by: GrantS | last post by:
I am needing to permit users to select files using the 'Open file' common dialog box. The format of the names of the files are along the names of: GB00((&X.001.jpg I am not able to show these...
3
by: Me | last post by:
I posted on this about two months ago and got no response. I am creating an app in which the user needs to select a file somehow and then have its full path put into a text box (or label). I am...
0
by: Ofelia | last post by:
Hi, I'm new to this forum and to Perl language but I would like to ask for your help. I'm working in Linux and the files I need to process are in the format “file.gz”. I created a script which...
1
by: dryajov | last post by:
Hi I'm not sure if this should go here in the first place, this is more likely an ODBC driver issue. I'm having the strangest behavior when trying to do an insert into an access database from a...
1
by: mathew1 | last post by:
How can I open a file whose file name is stored in a variable Thank you in advance
2
by: kof0018 | last post by:
Hi, all I have a questions to obtain the current open file's path using C#. And I try using the Process.GetProcesses().MainWindowTitle, it jsut get the opened file's name, not the opened file's...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.