View Single Post
 
Old 11-27-2013, 10:29 AM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Aha! Good call, macropod. Funky, this is why I've gotten into the habit of qualifying almost everything in VBA; there are just too many ways to lose track of what the default may be. Besides, a lot of programs I write work with multiple worksheets, workbooks etc. So I find it a useful habit to just define a variable for each object I'll be working with, something like this:
Code:
Set woIp = ThisWorkbook
Const wnOp = "TLXI.xlsx"
If Not Exists(Workbooks,wnOp) Then Abend "Can't find workbook " & wnOp
Set woOp = Workbooks(wnop)
Set soIp = woIp.Worksheets("Misc")
woOp.Worksheets.Add
set soOp = ActiveWorksheet
soOp.Name = "New"
Once I have all the objects defined, then for the rest of the program I can refer to soIp.Cells, woOp.SaveAs and so on without worrying that my program will do something unexpected. That is, programs almost always do something unexpected, but this cuts down on the puzzlement.
Reply With Quote