MS Office Forum / Word / Programming / February 2005
Minimize app vs. Not Visible App
|
|
Thread rating:  |
zSplash - 24 Feb 2005 20:41 GMT My code takes several minutes to "run", and I want the enduser to not have to "watch" all the rigamarole. I have a progress bar, which lets them know how the code is progressing, but because my code opens, closes, and adds new documents, among other things, I want to keep that from view.
I have tried to make the application not visible, but evidently some properties/methods don't work in that state. I have tried (when adding a new document, for example), to just make the added document not visible, but then my code is stuck in never-neverland, between the (now closed) added document and the active document. I have also unsuccessfully tried screenupdating = false and windowstate = wdWindowMinimize.
What is the preferred way to allow long code to run, with nothing being visible to the enduser but the progress bar?
TIA
Jezebel - 24 Feb 2005 21:39 GMT There are no properties that don't work with Word not visible, unless you are using the Selection object and Windows/Panes, etc. You can easily write your code to eliminate these. Your code will run much faster, apart from anything else.
Your problem with the app minimized is also sloppy coding. For one thing, don't use ActiveDocument except as a starting point. Hard to suggest anything beyond that, without knowing more about your code. Word goes into nevernever land only if you send it there.
> My code takes several minutes to "run", and I want the enduser to not have > to "watch" all the rigamarole. I have a progress bar, which lets them [quoted text clipped - 15 lines] > > TIA zSplash - 24 Feb 2005 21:55 GMT Thanks so much for the constructive advice, Jezebel. I'm sorry my coding is sloppy; I'm sure yours, even as a beginner, was awesome.
I am using Selection object -- how do I eliminate that? I didn't use ActiveDocument elsewhere -- excuse my misuse of the term. I just tried to explain where the problem was occurring.
st.
> There are no properties that don't work with Word not visible, unless you > are using the Selection object and Windows/Panes, etc. You can easily write [quoted text clipped - 25 lines] > > > > TIA Jonathan West - 24 Feb 2005 22:44 GMT > Thanks so much for the constructive advice, Jezebel. I'm sorry my coding > is [quoted text clipped - 3 lines] > ActiveDocument elsewhere -- excuse my misuse of the term. I just tried to > explain where the problem was occurring. Most things that you do with the selection you can do with a Range object instead.
if the macro starts out by using the selection, put this at the start of the macro
Dim myRange as Range Set myRange = Selection.Range
Then, throughout the rest of the macro, you can do a search & replace, replacing Selection with myRange.
In many cases, that is all you will need to do. Your macro will probably run faster as a result, because the screen isn't having to update so much.
 Signature Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup
zSplash - 25 Feb 2005 00:17 GMT Thanks so much for the specific direction. I have tried what you suggest, but now I get errors ("Method or data member not found.") at places like:
myRange.HomeKey Unit:=wdLine [which had been] Selection.HomeKey Unit:=wdLine
I guess the Range object doesn't have the HomeKey method (??).
Anyway, here's a snippet of my code. I'm more than game to learn the Range object, but need a little more help, guys. TIA
X = 1 While Asc(MyRange) <> 13 MyRange.EndKey Unit:=wdLine, Extend:=wdExtend MyRange.Copy helpme = True 'to bypass open_doc events Documents.add DocumentType:=wdNewBlankDocument MyRange.Paste MyRange.Delete Unit:=wdCharacter, Count:=1 ActiveDocument.SaveAs FileName:="H:\CCall\c" & X & ".txt", FileFormat:=wdFormatText ActiveWindow.Close MyRange.HomeKey Unit:=wdLine 'add column of macro numbers MyRange.TypeText Text:="c" & X MyRange.TypeText Text:=vbTab MyRange.HomeKey Unit:=wdLine MyRange.MoveDown Unit:=wdLine, Count:=1 X = X + 1 Wend
> > Thanks so much for the constructive advice, Jezebel. I'm sorry my coding > > is [quoted text clipped - 18 lines] > In many cases, that is all you will need to do. Your macro will probably run > faster as a result, because the screen isn't having to update so much. Jezebel - 25 Feb 2005 00:23 GMT > Thanks so much for the specific direction. I have tried what you suggest, > but now I get errors ("Method or data member not found.") at places like: [quoted text clipped - 55 lines] > run >> faster as a result, because the screen isn't having to update so much. Jezebel - 25 Feb 2005 00:29 GMT One of the points of using Ranges is that you don't need to move around them. So you're right, a range doesn't have methods like EndKey, HomeKey or MoveDown.
Perhaps you could explain what you're trying to do here: you start with an open document, then copy something into a new document, then add numbers to soemthing in the original document? -- at the start of each paragraph? cell?
But what is the looping all about? continue until you meet an empty paragraph? What are you trying to copy?
> Thanks so much for the specific direction. I have tried what you suggest, > but now I get errors ("Method or data member not found.") at places like: [quoted text clipped - 55 lines] > run >> faster as a result, because the screen isn't having to update so much. zSplash - 25 Feb 2005 07:13 GMT Thanks, guys, for your responses. I guess I'll have to try to figure out Range object, or else have the code flash across the screen. Selection just seemed so easy to use (I could immediately see if I selected the correct thing), while Range is less obvious to me....
You've pretty much got what I'm trying to do. The end user types a List (of names and "acct_numbers"), then my code deals with that List. I copy each line of the List to a text file, then modify the text file, then save the text file, then add additional #'s (macro #'s) to each line of the List, and save the List.
The only looping in this snippet is for the purpose you state -- to continue until I reach an empty line.
> Perhaps you could explain what you're trying to do here: you start with an > open document, then copy something into a new document, then add numbers to > soemthing in the original document? -- at the start of each paragraph? cell? > > But what is the looping all about? continue until you meet an empty > paragraph? What are you trying to copy? Jezebel - 25 Feb 2005 07:38 GMT OK, for starters, try experimenting with this ... your source document has a list of numbers, each on its own line (ie, in a paragraph of its own)
Dim pPar as Word.Range Dim pSrcDoc as Word.Document Dim pTargetDoc as Word.Document
Set pSrcDoc = ActiveDocument For each pPar in pSrcDoc.Paragraphs Debug.Print pPar.Text Set pTargetDoc = Documents.Add pTargetDoc.Range = pPar.Text pTargetDoc.SaveAs FileName:=.... pTargetDoc.Close Next
It's not everything you're trying to do, but it might help you understand the method. MUCH easier than moving the selection around, once you get the hang of it.
> Thanks, guys, for your responses. I guess I'll have to try to figure out > Range object, or else have the code flash across the screen. Selection [quoted text clipped - 23 lines] >> But what is the looping all about? continue until you meet an empty >> paragraph? What are you trying to copy? zSplash - 25 Feb 2005 16:53 GMT Thanks so much Jezebel. I will try exactly what you say, and, hopefully, understand it. I really appreciate the help you and Jonathan have provided!
st.
> OK, for starters, try experimenting with this ... your source document has a > list of numbers, each on its own line (ie, in a paragraph of its own) [quoted text clipped - 43 lines] > >> But what is the looping all about? continue until you meet an empty > >> paragraph? What are you trying to copy? Jonathan West - 25 Feb 2005 00:48 GMT > Thanks so much for the specific direction. I have tried what you suggest, > but now I get errors ("Method or data member not found.") at places like: [quoted text clipped - 28 lines] > X = X + 1 > Wend There are a few methods which are available for the Selection which are not available for a Range, and you have with unerring accuracy found most of them!
If your paragraphs take up a single line each, then you can use the Move method instead of HomeKey and EndKey, and set the Unit pareameter to wdParagraph and the value to 1 or -1 respectively. That will move the range the appropriate distance.
 Signature Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup
Jezebel - 24 Feb 2005 23:13 GMT Wasn't meant to be rude. I'm KNOW my beginner code was execrable. Just the problems you describe are -- well, bugs. :)
In place of the Selection object you use Range variables. In fact, the Selection is just a special kind of Range object anyway -- you'll see that it has all the same properties. The main difference is that the Selection object needs access to the visual display, and you can have only one of them. Post a code snippet ....
The other problem that beginners tend to run into is moving around the document using the Selection and move methods. Better (and MUCH faster) is to work directly with the underlying objects.
> Thanks so much for the constructive advice, Jezebel. I'm sorry my coding > is [quoted text clipped - 42 lines] >> > >> > TIA
|
|
|