S
StevenM
I realize that my questions here might be simply a matter of taste and
programming style, but I’m also wanting to run this pass those on this forum
to make sure I’m not getting myself into trouble by making unwarranted
assumptions.
I’ve been using the following to open a new document and to set a range
object.
Dim oDoc as Document
Dim oRange as Range
Set oDoc = Documents.Add(sTemplate)
Set oRange = Selection.Range
But, if I’m not mistaken, this is the same as:
Set oDoc = Documents.Add(sTemplate)
Set oRange = oDoc.Range
Yes? Is there a difference between them? (And doesn’t the latter make more
sense? At least it took me some time to figure out that by creating a new
document, the new document as now the active document, and so here
“Selection†= “oDoc,†yes?)
Also, I’ve been passing both the document object and range object to
functions, would it be simpler to pass only the range object and when/if I
need the document object to recreate it such as:
Function Xyz(ByVal oRange as Range, ... etc.)
Dim oDoc as Document
Set oDoc = oRange.Parent
It also seems to me that:
Dim oStyle as Style
Set oStyle = oDoc.Styles("Some Styleâ€)
is the same thing as:
Set oStyle = oRange.Parent.Styles("Some Sytle")
Both statements appear to work equally well, the only difference appears to
be that the IntelliSense doesn’t work with “oRange.Parent,†but the code ran
fine.
It also seems to me that one could even dispense with creating a styles
object and write:
Dim ptFontSize as Single
ptFontSize = oRange.Parent.Styles(“Some Styleâ€).Font.Size
I apologize if all this seem trivial, but it has taken me hours to figure
all this out. My question is this: Instead of passing both a document object
and its range object to another function, wouldn’t it simplify things to pass
only one, and then use that object to create the other if needed? The reason
I ask is that my current project works with three documents, and passing
three ranges, plus one or two document objects, as well as other variables.
It creates a long and cumbersome augment/parameter list. Or am I better off
with a long augment/parameter list?
I would greatly appreciate any feedback on the above.
Steven Craig Miller
programming style, but I’m also wanting to run this pass those on this forum
to make sure I’m not getting myself into trouble by making unwarranted
assumptions.
I’ve been using the following to open a new document and to set a range
object.
Dim oDoc as Document
Dim oRange as Range
Set oDoc = Documents.Add(sTemplate)
Set oRange = Selection.Range
But, if I’m not mistaken, this is the same as:
Set oDoc = Documents.Add(sTemplate)
Set oRange = oDoc.Range
Yes? Is there a difference between them? (And doesn’t the latter make more
sense? At least it took me some time to figure out that by creating a new
document, the new document as now the active document, and so here
“Selection†= “oDoc,†yes?)
Also, I’ve been passing both the document object and range object to
functions, would it be simpler to pass only the range object and when/if I
need the document object to recreate it such as:
Function Xyz(ByVal oRange as Range, ... etc.)
Dim oDoc as Document
Set oDoc = oRange.Parent
It also seems to me that:
Dim oStyle as Style
Set oStyle = oDoc.Styles("Some Styleâ€)
is the same thing as:
Set oStyle = oRange.Parent.Styles("Some Sytle")
Both statements appear to work equally well, the only difference appears to
be that the IntelliSense doesn’t work with “oRange.Parent,†but the code ran
fine.
It also seems to me that one could even dispense with creating a styles
object and write:
Dim ptFontSize as Single
ptFontSize = oRange.Parent.Styles(“Some Styleâ€).Font.Size
I apologize if all this seem trivial, but it has taken me hours to figure
all this out. My question is this: Instead of passing both a document object
and its range object to another function, wouldn’t it simplify things to pass
only one, and then use that object to create the other if needed? The reason
I ask is that my current project works with three documents, and passing
three ranges, plus one or two document objects, as well as other variables.
It creates a long and cumbersome augment/parameter list. Or am I better off
with a long augment/parameter list?
I would greatly appreciate any feedback on the above.
Steven Craig Miller