wordbasic conversion question.

  • Thread starter charlie.planetxsolutions
  • Start date
C

charlie.planetxsolutions

hi there,

i have some wordbasic code that i am attempting to convert to vba.

the following code just provides a 'type mismatch' error at the
ActiveDocument.Sections line... nothing i seem to do makes it funtion.
additionally, the original WordBasic.ToolsProtectSection line doesn't seem to
unprotect the section for me either.

If sDocumentCreatedBy$ <> "PROVISION_LIST_DOCUMENT" Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
Password:=sPassword$, NoReset:=True
'WordBasic.ToolsProtectDocument DocumentPassword:=sPassword$,
NoReset:=0, Type:=2

For i = 1 To iNumProtectedSections

If iUnprotectSectionNumbers__(i) > 0 Then
iSectionNumber$ = iUnprotectSectionNumbers__(i)
MsgBox "Debug: about to unprotect section: " +
Str(iSectionNumber$) + "."
ActiveDocument.Sections(iSectionNumber$).ProtectedForForms = False
'WordBasic.ToolsProtectSection
Section:=iUnprotectSectionNumbers__(i), Protect:=0
End If
Next

Else...

any assistance greatly appreciated.
 
J

Jay Freedman

The $ character at the end of iSectionNumber$ declares it as a String
variable. VBA is complaining about trying to use that string as the index
into the ActiveDocument.Sections collection. Either remove the $ from all
occurrences of iSectionNumber or just use the iUnprotectSectionNumbers__(i)
value directly.

This is an excellent illustration of why VBA variables should be explicitly
declared in Dim statements
(http://www.word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm). You should
declare

Dim iSectionNumber As Integer

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top