473,383 Members | 1,872 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,383 software developers and data experts.

{Excel} Regarding Relative Path in Macros

Hi All,

I am using absolute path in my macro code, but i want to change it to relative path. I am not sure what exactly relative path will do how to use relative path in macro. Please can any one give me any idea on this.

Here is my path in code
Expand|Select|Wrap|Line Numbers
  1. Set Wkb2 = Workbooks.Open(Filename:="C:\Documents and Settings\admin\Desktop\Aezaz\BNP_Folder\Input\Manpower_Master_Forecast_10_BNPPISPL.xls")
  2. Wkb2.Activate
Thanks in Advance

Teja
Jun 18 '10 #1
6 8532
NeoPa
32,556 Expert Mod 16PB
You can use the value in ThisWorkbook.Path to help you work out a relative path. Does this help?

Welcome to Bytes!
Jun 18 '10 #2
@NeoPa
Thanks for quick reply,

I have some input excel files in one folder, i am writting macro code in different excel workbook. I have to specify the location on input file as mention above in my 1st post. In that i am using absolute path that i want to make relative. Can you tell me what i need to do.

Reagards
Teja
Jun 19 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. Set Wkb2 = Workbooks.Open(Filename:=ThisWorkbook.path & "\BNP_Folder\Input\Manpower_Master_Forecast_10_BNPPISPL.xls")
  2. Wkb2.Activate
Your not giving us enough information to work with. Relative to what? Ive given an example of using the path of the current workbook, and concatanating a string with the rest of the folder name.

Without more information we can't really help you.
Jun 19 '10 #4
NeoPa
32,556 Expert Mod 16PB
It's hard to know what more you need Teja. Do you understand the concept of relative path? In this case I'm working on the principle that you want to open other workbooks (whose filenames you already know) from the same folder as that of the currently running workbook. ThisWorkbook.Path supplies the part that you don't have. You can use this string value to create an absolute path pointing directly to the file you require (As illustrated in Smiley's post #4). If you require the path of the workbook currently being worked upon (usually the same but may be different from the one whose code is running) then you can use ActiveWorkbook.Path instead.

An alternative would be to use the ChDir statement to set the current working directory and then open the file giving a relative name :
Expand|Select|Wrap|Line Numbers
  1. ChDir ThisWorkbook.Path
  2. Set Wkb2 = Workbooks.Open(Filename:="Manpower_Master_Forecast_10_BNPPISPL.xls")
  3. Wkb2.Activate
This is unusual however, as it effects other things than simply the code, and the code has all the information it needs to provide the full reference anyway.
Jun 19 '10 #5
@NeoPa
Thanks NeoPa,
I got how to use relative path in macro, thanks for explaining me about it. Its working now for me.

Thanks once again

Teja
Jun 21 '10 #6
NeoPa
32,556 Expert Mod 16PB
Oh good. I'm glad that helped :)
Jun 21 '10 #7

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

Similar topics

4
by: Richard | last post by:
We are distributing a VS2003 solution to our customers that includes a .NET assembly (dll file) and a sample project for how to use the dll. The customer can then customize the sample or add a new...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
8
by: dw | last post by:
Hello, all. I have a site that I'm testing on my LOCALHOST and also on a remote server, depending on whether I'm at work or at home. I don't want the OLEDBDATAAdapter to be pointing to the remote...
6
by: openleren | last post by:
Hi all, how can I use a relative path in my web.config file for an Access db?: Instead of using <configuration> <appSettings> <add key="conAccess" value="microsoft.jet.oledb.4.0;data...
4
by: Win, Pats | last post by:
I have a snippet of HTML that I inject into a number of pages throughout my Web site at runtime. My problem is that I'm not getting the image to appear in all documents into which this snippet is...
2
by: Jordan Richard | last post by:
Put another way, is there any way I can tell ASP.NET to convert a path (imbedded in a string variable, "~/images/some_image.gif") to a root-relative path, that the client will understand, for the...
1
by: damiensawyer | last post by:
Hi all, I hope that this question isn't too simple... I am storing all of my webforms in a /forms directory (with the exception of Default.aspx). I have created the following code in...
1
by: Coaster | last post by:
If I am calling File.CopyTo make a backup copy of a remote file on a remote machine where the source and destination locations are both on the remote machine would it be faster to call the function...
2
by: BD | last post by:
Hi there. Using 8.2 on Windows. I have a situation where I have a db backup, which I want to deploy to a group of developer workstations. The target directory for the database files will be...
0
by: swatii | last post by:
I am developing application in c#.net and I am using crystal reports. I want to dynamically load crystal report in report document so that from the same form I can access all the reports. for this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.