View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default File Path Issue in Excel 2016 for Mac

GS wrote:

GS wrote:

Sub whereAmI()
Cells(1, 1).Value = ActiveWorkbook.Path
End Sub

Just a minor point, but depending on context it's a very important point!

VBA 'best practice' suggests:

- use ActiveWorkbook only when the code is acting on or referencing a
workbook other than itself;

- use ThisWorkbook when code refs the workbook running the code.

Good point.


I figured since you program in other languages that you'd pick up on the
'This' part of an object ref-ing itself!


I just put down the first thing that came to mind, and didn't really put any
thought into it. Since it's meant to be a one-time-only sorta thing, I'm not
terribly worried about it. (Also, I'm much more used to Activewhatever,
because my code is often run from the personal macro workbook rather than the
workbook being affected.)


Yeah, nothing 'wrong' with that; -my stuff in PERSONAL.xls is configured that
way too! Given the scenario it's perfectly acceptable. Different story, though,
if the workbook was saved hidden, or was an addin, or Excel had one of its
common burps during the load process.

Are you aware that if the file gets corrupted the Workbook_Open event may not
even fire? I stopped using it many ions ago and replaced the open/beforeclose
events with the autorun macros Auto_Open and Auto_Close and redirect from
there.

FWIW
I've just got into the habit of following best practice rules in a more strict
way than most VBAers, more so now due to the strictness in programming in C#
more recently, but mostly because I'm also a long-time dedicated follower of
the "Professional Excel Development" principles which also strongly advocate
following best practice rules.

Your helpful contributions here are appreciated; -I hope you keep following
thess Excel NG

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion