473,659 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using macros to open a file whose path can be varied

1 New Member
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:\m ydoc\myfile\Dat a.xlsx", _
UpdateLinks:=3

suppose I have to move this file to a different path: C:\newdoc\newfi le\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 3754
Luuk
1,047 Recognized Expert Top Contributor
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
8760
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 produces an output file repeatedly, simulating the input file separately for each replicate. The error occurs when trying to open the input file to write out the new data. The problem is difficult to reproduce since it only shows up once every few...
0
1639
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 web address like window.open(http://.........). I have been asked to find out if it is possible to do something similar but instead opening a file located on my web server e.g.(G:\psh-4.pdf). I would like to be able to display the file in the web...
1
4505
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 another field for the Access database name. I would like to replace this with a Open file Dialog box. Could you please share with me the best way or the easiest way to accomplish this task. Thanks for you time!
3
1987
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 files in the dialog box for selection. I do need to use filters (cannot use (*.*| all files) I tried using the filter *.*.jpg without success. The filter string I have tried is:
3
1361
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 using the Open File Dilog Bo to do this. The problem is that the file they need to select is an execitable (exe). When theyhighlight it and then select the Open button it attempts to run the program. This only seems to happen in Windows 9x but may be...
0
2658
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 should decompress, open and then delete nearly 400 files. To do so I use "open FILEPT, "zcat $filename|"". In the beginning the script works fine, but after about 300 files processed I get an error on Open function: “proc: Could not open file...
1
2816
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 C++ application, thru ODBC. I'm able to successfully open a connection to the DB and perform selects, but when I try to do an insert the strangest thing happens, ODBC throws an error saying that it can't open the "dba.mdb" file, which is not the db...
1
2020
by: mathew1 | last post by:
How can I open a file whose file name is stored in a variable Thank you in advance
2
4258
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 path. Dose anyone has any idea can help me to get the complete file path? for example:
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.