#1
|
|||
|
|||
Word for Mac 2011: Problems accessing Text Boxes programmatically
I’ve recently moved a little app I wrote in VBA which runs fine on Windows Word 2010 to Mac Word 2011. Ideally, I would like to to seamlessly work on both platforms.
I’m using legacy form fields. (They are called Text Form Field on Word for Windows, Text Box Form Control on Word for Mac) The Text Boxes I am accessing within VBA have been named: firstName, lastName etc. within the Word document itself. Here are some code snippets Const FIRSTNAME = 1 Const LASTNAME = 2 …… Const MAXBOOKMARKS= 22 Dim strRepBookMarks(MAXBOOKMARKS) As String strRepBookMarks(FIRSTNAME) = "firstName" strRepBookMarks(LASTNAME) = "lastName" …… For iBookMark = 1 To MAXBOOKMARKS docReport.FormFields(strRepBookMarks(iBookMark)).R esult = docBase.FormFields(strRepBookMarks(iBookMark)).Res ult Next iBookMark However, I get the following error message when executing it on Word for Mac: Run-time error ‘5941’ The requested member of the collection does not exist. From the Immediate Window, I get the same error (iBookMark is 1) on: debug.print docBase.FormFields(strRepBookMarks(iBookMark)).Res ult However, on: debug.print docBase.FormFields("firstName").Result it returns the string: Mary which is the current value of the text box within the word document. Some other information: debug.print strrepbookmarks(firstname) returns the string: firstName debug.print firstname returns 1, which is the value of the Constant I previously defined What appears to be happening, is that docBase.FormFields(strRepBookMarks(iBookMark)).Res ult is being evaluated as: docBase.FormFields(1).Result rather than: docBase.FormFields(“firstName”).Result which is what I think it should be given that strRepBookMarks(iBookMark) = “firstName” This works correctly when running on Windows Word 2010. I have also executed the debug.print statements shown above on Word for Windows and it works as expected. ( By this I mean from the Immediate Window on Word for Windows, both debug.print docBase.FormFields(strRepBookMarks(iBookMark)).Res ult AND debug.print docBase.FormFields("firstName").Result return the string: Mary which is the current value of the text box within the word document. Any ideas….? |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word 2013 Text boxes on everything, can't select across multiple boxes | 1Kurgan1 | Word | 2 | 10-31-2016 01:20 AM |
Drawing lines between text boxes which have actual text within the text boxes | RHODIUM | Word | 6 | 10-01-2016 04:43 PM |
Word 2011 for Mac - problems with table of contents | tepose | Word | 1 | 09-28-2014 03:36 PM |
Can't copy text boxes in PowerPoint 2011 for Mac | dkhanal | PowerPoint | 2 | 09-08-2014 01:26 PM |
programmatically inserting hidden text into a Word 2010 table | epid011 | Word VBA | 16 | 12-30-2013 11:29 AM |