ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I reference a directory for a file in VBA that is different (https://www.excelbanter.com/excel-programming/358556-how-do-i-reference-directory-file-vba-different.html)

SFGiants Fan

How do I reference a directory for a file in VBA that is different
 
I have been successful in writing code that allows me to print a worksheet
within my workbook and then open up a Word document and print it as well. I
basicly cut and pasted VBA from suggestions by those of you that use this
discussion group. The Word document is located on my harddrive in the same
subdirectory as my Excel workbook. This happens to be my C:\ drive. I use
this same workbook file at work where the drive is F:\. Is there a way of
referencing the document file without the directory drive so that it just
assumes that it resides in the same subdirectory as the Excel file that is
executing the macro? What I have been doing, which I know is rediculous, is
changing the VBA reference drive based on the computer that I am using. Any
help with this would be greatly appreciated. Thanks, Steve

Kletcho

How do I reference a directory for a file in VBA that is different
 
You could put in an input box asking for the drive to use. Something
like:

DriveLetter = InputBox("Please enter a drive letter")

Then use that in your code when you determine the address.


JMB

How do I reference a directory for a file in VBA that is different
 
Thisworkbook.Path & Application.PathSeparator & "Yourfilename"



"SFGiants Fan" wrote:

I have been successful in writing code that allows me to print a worksheet
within my workbook and then open up a Word document and print it as well. I
basicly cut and pasted VBA from suggestions by those of you that use this
discussion group. The Word document is located on my harddrive in the same
subdirectory as my Excel workbook. This happens to be my C:\ drive. I use
this same workbook file at work where the drive is F:\. Is there a way of
referencing the document file without the directory drive so that it just
assumes that it resides in the same subdirectory as the Excel file that is
executing the macro? What I have been doing, which I know is rediculous, is
changing the VBA reference drive based on the computer that I am using. Any
help with this would be greatly appreciated. Thanks, Steve


Jim Cone

How do I reference a directory for a file in VBA that is different
 
Give this a try (from the Excel workbook)...

ThisWorkbook.Path & "\NameOfWordDocument.doc"
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"SFGiants Fan" <SFGiants

wrote in message

I have been successful in writing code that allows me to print a worksheet
within my workbook and then open up a Word document and print it as well. I
basicly cut and pasted VBA from suggestions by those of you that use this
discussion group. The Word document is located on my harddrive in the same
subdirectory as my Excel workbook. This happens to be my C:\ drive. I use
this same workbook file at work where the drive is F:\. Is there a way of
referencing the document file without the directory drive so that it just
assumes that it resides in the same subdirectory as the Excel file that is
executing the macro? What I have been doing, which I know is rediculous, is
changing the VBA reference drive based on the computer that I am using. Any
help with this would be greatly appreciated. Thanks, Steve


All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com