Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default PATH Update; VBA problems

I have a cell "F10" on sheet 1 that contains the PATH for the file. I
have the following code which is working fine:

Private Sub Workbook_Open()
Application.Caption = ThisWorkbook.Path
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Caption = ""
End Sub

Upon opening the book, the Path is listed in the caption bar and
updates F10 with the location. Upon closing it removes it from the
caption bar.

What I want to do is have that cell updated anytime the file is saved.
I tried the following code. It did not give me an error but it also
did not give me my desired result.

Private Sub Workbook_AfterSave()
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

What am I missing?

Thank you for your help.

RU
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default PATH Update; VBA problems

RU,

There isn't an After_Save Event.
There is a Before_Save which should do the trick for you.

For a lit of Workbook events, from the VBA Editor, Double
click on THisWorkbook in the "Projects", select "Workbook"
from the left dropdown in the panel to the right and then check
the right dropdown. There you'll have a list of all of the valid
workbook events.

John

"RU_Powers" wrote in message
...
I have a cell "F10" on sheet 1 that contains the PATH for the file. I
have the following code which is working fine:

Private Sub Workbook_Open()
Application.Caption = ThisWorkbook.Path
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Caption = ""
End Sub

Upon opening the book, the Path is listed in the caption bar and
updates F10 with the location. Upon closing it removes it from the
caption bar.

What I want to do is have that cell updated anytime the file is saved.
I tried the following code. It did not give me an error but it also
did not give me my desired result.

Private Sub Workbook_AfterSave()
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

What am I missing?

Thank you for your help.

RU



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default PATH Update; VBA problems FOLLOW UP


Thanks for the pointer on the pull down menu.

I modified the code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

It works - sort of. When I save, the function does occur but does not
display immediately. This is what I mean.

File is in Folder A
I 'Save As' into Folder B
(When I look at the cell F10, it still says Folder A)
As soon as I click on Save As again then the cell updates it's
reference. (I don't even have to actually save, just clicking in save
in the menu does it.)

Is there a way to make it update/refresh? I don't think so but I
thought I would ask those who know more then me.

I have added code for BeforePrint and if a person saves the file to a
location and then chooses to print, the correct location will appear.
That may be my only solution.

SIDE QUESTION. Is there a way to get the file name with the path?
That is not as important to me as the Path, but if it could be done
easily that would be a bonus.

Thanks again John (and any others who reply)

RU


On Mon, 18 Aug 2003 19:34:39 -0400, "John Wilson"
wrote:

RU,

There isn't an After_Save Event.
There is a Before_Save which should do the trick for you.

For a lit of Workbook events, from the VBA Editor, Double
click on THisWorkbook in the "Projects", select "Workbook"
from the left dropdown in the panel to the right and then check
the right dropdown. There you'll have a list of all of the valid
workbook events.

John

"RU_Powers" wrote in message
...
I have a cell "F10" on sheet 1 that contains the PATH for the file. I
have the following code which is working fine:

Private Sub Workbook_Open()
Application.Caption = ThisWorkbook.Path
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Caption = ""
End Sub

Upon opening the book, the Path is listed in the caption bar and
updates F10 with the location. Upon closing it removes it from the
caption bar.

What I want to do is have that cell updated anytime the file is saved.
I tried the following code. It did not give me an error but it also
did not give me my desired result.

Private Sub Workbook_AfterSave()
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

What am I missing?

Thank you for your help.

RU



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default PATH Update; VBA problems FOLLOW UP

RU,

Here's a workaround.....
I never could figure out exactly why it works but it does.
The premise is to use the Application.OnTime method
to create a one second delay before running the code.
I'm guessing that this gives Excel an opportunity to save
the file prior to running the code.

Anyway......
In the Workbook.Before_Close Event:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Application.OnTime Now + TimeValue("00:00:01"), "UpdatePath"
End Sub

And now in a regular module:

Sub UpdatePath()
Sheet1.Range("F10").Value = ThisWorkbook.Path & "\" & ThisWorkbook.Name
End Sub

You'll note that I added "ThisWorkbook.Name" which should answer
your other question.

John

"RU_Powers" wrote in message
...

Thanks for the pointer on the pull down menu.

I modified the code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

It works - sort of. When I save, the function does occur but does not
display immediately. This is what I mean.

File is in Folder A
I 'Save As' into Folder B
(When I look at the cell F10, it still says Folder A)
As soon as I click on Save As again then the cell updates it's
reference. (I don't even have to actually save, just clicking in save
in the menu does it.)

Is there a way to make it update/refresh? I don't think so but I
thought I would ask those who know more then me.

I have added code for BeforePrint and if a person saves the file to a
location and then chooses to print, the correct location will appear.
That may be my only solution.

SIDE QUESTION. Is there a way to get the file name with the path?
That is not as important to me as the Path, but if it could be done
easily that would be a bonus.

Thanks again John (and any others who reply)

RU


On Mon, 18 Aug 2003 19:34:39 -0400, "John Wilson"
wrote:

RU,

There isn't an After_Save Event.
There is a Before_Save which should do the trick for you.

For a lit of Workbook events, from the VBA Editor, Double
click on THisWorkbook in the "Projects", select "Workbook"
from the left dropdown in the panel to the right and then check
the right dropdown. There you'll have a list of all of the valid
workbook events.

John

"RU_Powers" wrote in message
...
I have a cell "F10" on sheet 1 that contains the PATH for the file. I
have the following code which is working fine:

Private Sub Workbook_Open()
Application.Caption = ThisWorkbook.Path
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Caption = ""
End Sub

Upon opening the book, the Path is listed in the caption bar and
updates F10 with the location. Upon closing it removes it from the
caption bar.

What I want to do is have that cell updated anytime the file is saved.
I tried the following code. It did not give me an error but it also
did not give me my desired result.

Private Sub Workbook_AfterSave()
Sheet1.Range("F10").Value = ThisWorkbook.Path
End Sub

What am I missing?

Thank you for your help.

RU





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup - Update Path Clyde Dickson[_2_] Excel Worksheet Functions 3 August 26th 09 01:44 PM
Excel problems after winXP sp3 update jamoldover Excel Discussion (Misc queries) 4 May 28th 08 04:25 PM
auto file path update when excel sheet moved to another directory. GNSBoy Excel Discussion (Misc queries) 1 August 31st 05 07:46 PM
Recurring Problems with Links with Full Path Names JMcBeth Excel Discussion (Misc queries) 1 February 4th 05 10:11 PM
More UDF problems; some won't update, some won't stop running! Keith R[_3_] Excel Programming 0 August 1st 03 02:01 PM


All times are GMT +1. The time now is 03:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"