|
-
Sep 9th, 2000, 10:43 AM
#1
Just add On Error Resume Next to ignore any errors.
Code:
On Error Resume Next
'clear the Err object
Err.Clear
WordApp.Selection.MoveDown Unit:=wdLine, Count:=1
WordApp.Selection.MoveRight Unit:=wdCell
If Err Then
'Houston we have a problem
Exit Sub 'or function
End If
WordApp.Selection.TypeText Text:=txtEndUser
Good luck!
-
Sep 9th, 2000, 04:20 PM
#2
Junior Member
Joacim,
All I can say is tanks 'again' - worked a treat.
Can I trouble you for one more. This may not be worth the trouble and I can live without it.
As standard all of our Word file footers contain a table. The standard is to place a blank line in the footer before inserting the table (just means that a nice space is left between the body of the document and the footer).
Sometimes people get careless and the space is not put in.
When I get into the footer, I automatically perform a WordApp.Selection.MoveDown Unit:=wdLine, Count:=1 to skip the blank line and get into the table.
Is there any way to tell - when I get into the footer if I have landed on a blank line or have I landed in a table??
Thanks,
Graham.
-
Sep 9th, 2000, 04:34 PM
#3
Again I think the easiest way is to use the error trapping you already put in the code.
Start by trying to move in the table if an error is raised then you're not in the table so move down one line and try again.
If an error is raised the second time assume you don't have a table.
Code:
On Error Resume Next
'clear the Err object
Err.Clear
WordApp.Selection.MoveRight Unit:=wdCell
If Err Then
'Okidoki we where not in a table so we move down
'a line and try again.
'But first we have to clear the Err object
Err.Clear
WordApp.Selection.MoveDown Unit:=wdLine, Count:=1
WordApp.Selection.MoveRight Unit:=wdCell
If Err Then
'We got a new error so we probably don't have any
'table here so bail out.
Exit Sub 'or function
End If
End If
WordApp.Selection.TypeText Text:=txtEndUser
'and the rest of the code....
Good luck!
-
Sep 9th, 2000, 04:41 PM
#4
Junior Member
Thanks, I should have thought of that.
I'm probably pushing my luck but..
I have recently installed VB6 and I mistakenly didn't install the help files so I am a bit stuck on a simple item.
When I get an error I want to bypass a section of the code to do with the table, I don't want to Exit Sub. (I presume I want to use the forbidden goto!!)
Can you please tell me how to goto a label or skip x lines of code.
Thanks.
Graham.
-
Sep 9th, 2000, 04:46 PM
#5
I'm NOT going to show you how to use GoTo but it's pretty easy to skip a few lines if an error is trapped:
Code:
On Error Resume Next
'clear the Err object
Err.Clear
WordApp.Selection.MoveRight Unit:=wdCell
If Err Then
'Okidoki we where not in a table so we move down
'a line and try again.
'But first we have to clear the Err object
Err.Clear
WordApp.Selection.MoveDown Unit:=wdLine, Count:=1
WordApp.Selection.MoveRight Unit:=wdCell
End If
If Err = 0 Then
'We didn't get any error so we are in a table
'Put the code that handles the table here
End If
'and the rest of the code here....
Good luck!
-
Sep 9th, 2000, 04:58 PM
#6
Junior Member
If Err = 0 Then - is exaclty what I was looking for.
Cheers
Graham.
(P.S. If you are ever in Dublin I owe you a pint - assuming you're old enough etc..)
-
Sep 9th, 2000, 05:06 PM
#7
Well I'm 32 so I guess I'm old enough!
I live in Sweden but if I start swimming now I suppose I'll be in Dublin in a couple of weeks 
But then you have to buy me a whiskey as well so I heat up
-
Sep 9th, 2000, 05:11 PM
#8
Junior Member
No problem.
Last question I promise (well tonight anyway)
On a previous occasion you gave me a routine to search sub-directories looking for Word files..
sFilename = Dir(sPath & "*.doc")
How can I add the search for "*.dot" files aswell (Word Template files) - can I use the OR or AND function.
Thanks
Graham.
-
Sep 9th, 2000, 05:19 PM
#9
Nope! You have to use two loops!
Code:
Dim i As Integer
Dim sExt As String
For i = 0 To 1
Ìf i Then
sExt = "*.doc"
Else
sExt = "*.dot"
End If
sFilename = Dir(sPath & sExt)
Do While Len(sFilename)
'the code that I don't remember right now
sFilename = Dir
Loop
Next
BTW I desided to walk over to Norway to make the swim a little bit shorter 
Best regards
[Edited by Joacim Andersson on 09-09-2000 at 06:24 PM]
-
Sep 9th, 2000, 05:21 PM
#10
Junior Member
I'll have a pint of Guinness and a Paddys Irish Whiskey waiting.
-
Sep 9th, 2000, 05:28 PM
#11
Junior Member
Should the
If i then
read
If i=0 then?
-
Sep 9th, 2000, 07:10 PM
#12
It really doesn't matter how you type it.
If i Then is True if i got any value other than zero. So in this case it's the same as typing If i = 1 Then.
Remember that False = 0 and True = -1 but anything that is not zero must be not false i.e. true.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|