I'm taking an ascii data file and converting/moving the data into MS Word tables.
It opens MS Word with the completed documemt.
I've gotten that part working well.
But here's the problem:
It can not make more that one word doc unless you close/restart the program.
If I try to make two documents in a row I get the following msg:
Code:
Runtime Error '462'
The remote server machine does not exist or is unavailble.
I get this error at line:
Set myRange = ActiveDocument.Content
I've only tried doing a second document after MS Word has been saved and closed.
Full code:
VB Code:
Private Sub InsertToTemplate3(Columns() As String, ByRef Year As Integer)
'inserts the preformayed columns text into the template then saves it
I know you say you aren't global MS Word objects, but certainly your myRange.Find.Execute statement must be prepended with a local Word object at least.
I know you say you aren't global MS Word objects, but certainly your myRange.Find.Execute statement must be prepended with a local Word object at least.
Boy did I just get a good scare!
I took the:
Code:
Set myRange = ActiveDocument.Content
bits from the help file.
The range object allows the use of vbCr while the find object doesn't
After reading Martins last post I changed the code to:
Code:
Set myRange = .ActiveDocument.Content
So that the dot would plug it into the MSWord object.
Then tried doing two doc's in a row. (After closing the 1st one.)
The code seemed to be working and was about half done when I black screened.
The comp rebooted itself and told me I didn't have a MBR!
Turned out to be a lose cable
Now the app is working fine when the first document gets closed before making a new one.
I'll do a test without closing the 1st doc now.
DAAAAMN.
Just found a new problem.
If the user closes the application while it's making a Word File both the program and Word stay open but hidden.
Should I make a new thread for this?
I added flag (m_bProcessing).
I check the flag in the Form_QueryUnload event
If True I warn the user, give them a chance to change their minds and turn the flag false if they still want to stop.
The 'Insertion' sub checks to see if the flag has changed and calls the '=Nothing' lines at the end of the sub.
But that didn't help!
I guess I could remove their option to kill the app while it's working, but that doesn't seem very Profes
Last edited by longwolf; Jun 30th, 2005 at 06:58 PM.
If they want to close the app it just hides itself until the job is done, then closes.
But the app may run for another 5 mins (it's adding about 1500 pieces of info to the file).
And the whole time WINWORD.EXE is pegging the CPU at about 98%.
Then, when it does close, it pops up a box asking if you want to save the changes.
Imagine an app asking to save changes 5 mins after you 'closed' it. AAAAAAAARRRRRRRRRGGGGGGG
I'm in the process of setting the Word Object to be global level.
That way I can move a bunch of this code to a module and just kill the obj when the user wants out.
I'll let you know how well it goes.
I'll probably be screaming again
Last edited by longwolf; Jun 30th, 2005 at 09:45 PM.
You need to post some of your code that inserts the data to the document. Maybe we can optimize it somehow.
I guess GetObject and this "Set MSWord = Word.Application" may be the same thing.
The app is formating tide tables for a give loc for a full year.
The reason it's taking so long is because I get an error if I try to insert any text over 256 chars long.
The basic insertion code hasn't changed sence my posting at 04:59 PM
I could have consolidated some of the insertions but those sections need different font sizes.
It was just easier to set the template Tags the correct font size(s) to begin with.
(It would also be nice if I could change the font for the MoonPhase Inserts and use the Moons from the WingDings 2 Font, but that a whole other problem)
BTW,
On that 'GetObject', I believe I saw a post here were that code caused someone a problem.
But I can't remember the details
Maybe you could use my method of creating the tables in Word, and saving it as a RTF file. Replace the entries with tags (I use [1] [2]) which you can then load as a document in a rtb in your app. Then you could replace [1] with your first item, and loop through the other ones. If you saved the moon phase X in a tag, you could prolly isolate it in between tags [mp1 X ], and then parse it out.
I am assuming the phase would be different for each chart.
The only problem I was having when the chart size changed. You shouldn't have that issue.
Use the WYSIWYG example at the M$ site so that you get actual dimensions for a print preview of your RTB.
Maybe you could use my method of creating the tables in Word, and saving it as a RTF file. Replace the entries with tags (I use [1] [2]) which you can then load as a document in a rtb in your app. Then you could replace [1] with your first item, and loop through the other ones. If you saved the moon phase X in a tag, you could prolly isolate it in between tags [mp1 X ], and then parse it out.
I am assuming the phase would be different for each chart.
The only problem I was having when the chart size changed. You shouldn't have that issue.
Use the WYSIWYG example at the M$ site so that you get actual dimensions for a print preview of your RTB.
Hi David,
My client was pretty specific about the layout and file type he wants.
But you've got me curious about you method, do you have an example somewhere?
The document is laided out something like a calander with 2 months sided-by-sided per page.
For the Moon phases, the app finds the 4 quarter moon dates for each month and adds an abbreviation to those days.
NM = New mon
FQ = First Quarter
FM = Full Mon
LQ = Last Quarter
Even if I get that working, I'd have to figure out how to change the chars and fonts at the same time, I'm guessing it'd use the Selection part of the Word Obj
Basically, I use .Find to search for a tag, then replace it with my output. This all fits in the cell of the table that I designed. For the headings on the top and bottom, I center and bold them, after I've written the rest of the info. I even copy in a different image into the third table (which has only one square cell that holds a picture).
I'm assuming that you could get the quarters to show up on the document. Then, you could just copy and paste them (I think) from one place to another. You might have to set the font, but you can use .SelFont for that, as you know.
I generate a receipt by replacing 45 fields, and formatting each one of them that includes about 25 prices, and a lot of detail that varies from page to page.
I can't post it, but I'll help you. Start with the WYSIWYG RTB from M$'s site.
It lets you work with a preview that is half the size of the printed page, like Word does.
It took a while to get everything working, and the biggest problem was trying to get an image next to text. I finally gave up and placed it on the bottom of the page (above the footer)
Hooray!
I think the beast is tamed.
I wouldn't call it house broken, but at least it seems to have stopped snapping at me
David,
I had a problem with the 'CreateObject' method.
If the user closed the 1st doc and tried to make a new one, CreateObject reported the MSWord object as still existing.
I adopted Marty's method and it's working fine.
One more task and I can (I hope) consider this job a complete success.
I want to replace the inserted Moon Phase 'tags' with the moon symbol fonts from Wingdings 2.
I can't seem to find a Chr$() value to create the First and Last Quarter Moon symbols.
To get those chars from the font I had to :
1. create an rtf file
2. use the Windows Character Map to copy them to the file
3 Load the new file into a RichTextBox.
I tried getting it directly from the richtextbox like this:
VB Code:
sFind = "NM"
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=rtbSmbls.SelRTF, _
Replace:=wdReplaceAll
But that pasted all the formating for the symbol, as if you opened an rtf file in Notepad.
So I created a sub to copy any one of the needed symbols to the windows clipboard.
Next I tried getting the symbol from the windows clipboard:
Thanks David,
But this is pasting onto a MS Word Document.
It'd be easy If I was making an rtf file.
I'm only using an rtf file to get the moon font symbols.
I can get the correct symbol and copy it to the windows clipboard or find it in the Richtextbox.
The Richtextbox is only used to hold those symbols.
I can also find and select the correct 'tags' in the MS Word doc.
I just can't seem to replace them with the symbols.
One more task and I can (I hope) consider this job a complete success.
I want to replace the inserted Moon Phase 'tags' with the moon symbol fonts from Wingdings 2.
I can't seem to find a Chr$() value to create the First and Last Quarter Moon symbols.
To get those chars from the font I had to :
1. create an rtf file
2. use the Windows Character Map to copy them to the file
3 Load the new file into a RichTextBox.
I tried getting it directly from the richtextbox like this:
VB Code:
sFind = "NM"
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=rtbSmbls.SelRTF, _
Replace:=wdReplaceAll
But that pasted all the formating for the symbol, as if you opened an rtf file in Notepad.
So I created a sub to copy any one of the needed symbols to the windows clipboard.
Next I tried getting the symbol from the windows clipboard:
But that pasted the entire original template into each of the tag positions, not good, lol
Any ideas on how to replace the tags and the fonts from the WINDOWS clipboard at the same time?
I responded in your other thread and what I said was that I can't figure out how to do it using SendKeys but Alt plus 386 on the number pad will produce that character if the font is wingdings 2. The trick is to use the number pad and I've seen references that say you can use something like SendKeys "%{Pad3}{Pad8}{Pad6}" but that gives an error.
David,
I had a problem with the 'CreateObject' method.
If the user closed the 1st doc and tried to make a new one, CreateObject reported the MSWord object as still existing.
I adopted Marty's method and it's working fine.
Update to this.
Marty's code had a problem if the user opened thier own Word Document while the program was running.
I made a hybred sub using both of y'alls codes.
It aint pretty, but it works
VB Code:
Public Function WordInitialize() As Boolean
Dim nRpt As Integer
On Error GoTo ErrorRoutine:
StartOver:
nRpt = FindWindow("OpusApp", vbNullString)
If nRpt = 0 Then
Set g_MSWord = New Word.Application
Else
Set g_MSWord = Word.Application
End If
WordInitialize = True
Exit Function
ErrorRoutine:
Select Case Err.Number
Case -2147023174
' The user has manually shut down Word, so we need to
For some reason I had to clear the clipboard before pasteing the new char to it.
Then use the PasteSpecial method in a loop.
It only replaces chars one at a time.