ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Write Procedure With Logic Test To Open File From Given Directory (https://www.excelbanter.com/excel-programming/322863-write-procedure-logic-test-open-file-given-directory.html)

Carl Bowman

Write Procedure With Logic Test To Open File From Given Directory
 
I need to write a procedure (not sure if this is what you call it) to cause
the file "data.xls" to be opened from path "C:\data\FEB" if the month is
February (evidenced by the text "FEB" in cell L45 in worksheet "Process") and
a file with the same name to be opened from path "C:\data\MAR" if the month
is March (evidenced by the text "MAR" in cell L45 of worksheet "Process").
This may be simple for some but I don't even know where to start. Thanks!

Markus Scheible[_2_]

Write Procedure With Logic Test To Open File From Given Directory
 
Hi Carl,

the file "data.xls" to be opened from path "C:\data\FEB"

if the month is
February (evidenced by the text "FEB" in cell L45 in

worksheet "Process") and


Try:

workbooks.Open FileName:="C:\data\" & Sheets
("Process").Range("L45").Value & "\data.xls"

Best

Markus

David Fam?

Write Procedure With Logic Test To Open File From Given Directory
 
OK,
if I've undestood, you want to open files with the same names and
different paths variable on a cell value. If this is correct, do as
follows:

Create a command button (from the Control Toolbox) and (in the Design
Mode - always selectable in the Control Tollbox Taskbar) double click
it. A macro screen will popup with a couple of lines written:

Private Sub CommandButton1_Click()
' Here write the following code
End Sub


The following code will create from cell L45 the right path and will
open the file (without ""):

' Starts Here

dim sPath as string
dim sPartialPath as string
dim sFileName as string

sFileName = "data.xls"
sPartialPath = worksheets("Process").cells(45,12).value
sPath = "C:\data\" & sPartialPath & "\" & sFileName

Workbooks.open(sPath)
' Finishes Here


Now, saving and then pushing the button (NOT in Design Mode) the
desired file should be opened.

Hope it Helps,
David

Carl Bowman

Write Procedure With Logic Test To Open File From Given Directory
 
Thanks a million Markus! This worked great and has opened up a whole new
world to me!

"Markus Scheible" wrote:

Hi Carl,

the file "data.xls" to be opened from path "C:\data\FEB"

if the month is
February (evidenced by the text "FEB" in cell L45 in

worksheet "Process") and


Try:

workbooks.Open FileName:="C:\data\" & Sheets
("Process").Range("L45").Value & "\data.xls"

Best

Markus


Carl Bowman

Write Procedure With Logic Test To Open File From Given Direct
 
Thanks, David. I will need to study this more. I was able to use the other
suggestion and it worked just fine. I still see some use for what you are
saying.

"David Fam?" wrote:

OK,
if I've undestood, you want to open files with the same names and
different paths variable on a cell value. If this is correct, do as
follows:

Create a command button (from the Control Toolbox) and (in the Design
Mode - always selectable in the Control Tollbox Taskbar) double click
it. A macro screen will popup with a couple of lines written:

Private Sub CommandButton1_Click()
' Here write the following code
End Sub


The following code will create from cell L45 the right path and will
open the file (without ""):

' Starts Here

dim sPath as string
dim sPartialPath as string
dim sFileName as string

sFileName = "data.xls"
sPartialPath = worksheets("Process").cells(45,12).value
sPath = "C:\data\" & sPartialPath & "\" & sFileName

Workbooks.open(sPath)
' Finishes Here


Now, saving and then pushing the button (NOT in Design Mode) the
desired file should be opened.

Hope it Helps,
David



All times are GMT +1. The time now is 02:01 PM.

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