Selection.MoveDown wdLine, 4, wdExtend doesn't work for one customer with Word 2013 RRS feed

  • Question

  • Hello,

    I have a problem with one of our many clients. We have an "old" software written in VB6.0 that uses Word automation. Since the software runs on various Windows-Plattforms with different Windows- and Office-versions it uses late binding. Usually we have relativly few problems and if we have them, they often happen to all users with a special version or patch level or else happen to more than one customer.

    Now I have the situation, that I have only one customer, who uses Office 2013 Home & Business, that has exactly one line of code seemingly not working (but not raising an error either).

    The code snippet is as follows:

    mDocument.Application.Selection.GoTo wdGoToBookmark, , , Bookmark
    If Bookmark = "Anlage7" Then
       mDocument.Application.Selection.MoveDown wdLine, 4, wdExtend
       MsgBox mDocument.Application.Selection.Text, vbOKOnly, "Debug"   'just to see what's selected
    End If

    Problem is the line  "mDocument.Application.Selection.MoveDown wdLine, 4, wdExtend", where "mDocument" is declared as "Word.Document". The variable "Bookmark" is set to "Anlage7" externally.

    The lines to select are in a table where one "row" internally consists of 5 rows and some fields are merged in some columns. So the first ".SelectRow" selects the actual first row and the ".MoveDown" is supposed to select the rest of the "row".

    It is working perfectly well in my various test environments with various Word versions and also with our other customers with various Word versions, even with Word 2013. Only for one customer it doesn't work, there is allways only the first row selected.

    I have read, that using the "Selection" might not be the best idea, that "Range" might be better, but the code is working for over  10 years now and the saying is "never touch a running system", isn't it?

    Has anyone an idea what could be the problem here?  Thanks in advance.

    Tuesday, March 18, 2014 3:23 PM

All replies

  • Hi MonaLisa ML,

    I created a new Word document and inserted a table according to your description, and copy your code with a minor change in the VBA editor. It worked fine with no errors. I used VBA not VB6.0, but it makes no difference.

    Sub Test()
        Dim Bookmark As String
        Bookmark = "Anlage7"
        Selection.GoTo wdGoToBookmark, , , Bookmark
        If Bookmark = "Anlage7" Then
        Selection.MoveDown wdLine, 4, wdExtend
        MsgBox Selection.Text, vbOKOnly, "Debug"
     End If
    End Sub

    The only probability I can think of is that you set the wrong name for the Bookmark, the name is not "Anlage7" but something else, so it didn't go into the IF...THEN...END IF code block. I think that's why only the first row is selected.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 19, 2014 12:20 PM
  • Hello Caillen,

    thanks for your efforts.

    The funny thing is, I tried my code via teamviewer in the customers document using vba too and it worked there too. That's what had me so baffled in the first place. When I executed my code as Macro in the document, all 5 rows got selected and copied correctly. But when the same code was executed via the vb6.0 program, it only showed me the content of the first line and only the first line got copied.

    I was wondering about the same things as you, that maybe "Bookmark" wasn't set to "Anlage7". But if I see my MsgBox with only the data of the first row inside the if-clause, that has to mean, that Bookmark is "Anlage7", otherwise the MsgBox inside the if-clause wouldn't be shown, or would it?

    The only difference to my table is, that in my table the first and the last column are merged, like 'Hello world' stood both in the first and the last column. And as said before: on my test environment and on other customer installations it works perfectly well.

    Do you have any other ideas?

    Thanks again,   Maren

    P.S: Could it be a setting in Word2013 that prohibits some actions from external applications which would be allowed from inside using macros? We compared all the Word options but found nothing obvious, no add-ins, no macros. The funny thing is, that all the other automation functions seem to work. Or could it be something in the environment of the customer (i.e. .NET-Framework, virus scanner etc.)?
    • Edited by MonaLisa ML Thursday, March 20, 2014 10:29 AM
    Thursday, March 20, 2014 9:41 AM
  • Hi MonaLisa ML,

    Please take a look at this documentation: Selection.MoveDown Method

    Check the return value of the MoveDown method to see if it works ok:

    unitsMoved = Selection.MoveDown(Unit:=wdLine, _
        Count:=4, Extend:=wdExtend)
    If unitsMoved = 4 Then Msgbox "MoveDown method works ok."

    Or try other WdUnits type like "wdRow".

    Another probability is that there might be some special characters in one of the cells of the table, Please double check the table.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 20, 2014 1:24 PM
  • Hello Caillen,

    I tried your suggestions first thing in the morning.

    Using 'wdRow' instead of 'wdLine' gave me a runtime error 4120 'Bad parameter'. Probably because Word thinks there are no 4 rows to move down. The first 'row' consists of 5 rows with merged cells in the first and last column and the second row is just a regular row (which gets deleted in the end).

    I tried to include some hardcopys to show the original document and the MsgBox results, but I got the following error:

    'Body text cannot contain images or links until we are able to verify your account.'

    Was does that mean? I'm logged in and my MSDN subscription is valid till 2015.

    So without images you will have to believe me when i state the following facts:

    I changed my code as follows:

    mDocument.Application.Selection.GoTo wdGoToBookmark, , , Bookmark
    If Bookmark = "Anlage7" Then
         lCount = mDocument.Application.Selection.MoveDown(wdLine, 4, wdExtend)
         MsgBox "After MoveDown " & lCount & ":" & vbCrLf & mDocument.Application.Selection.Text, vbOKOnly, "Debug"
    End If

    When running that code on the customers pc I got a MsgBox saying:

    "After MoveDown 0:" followed by the content of the first line.

    Which shows that 'MoveDown' hasn't worked.

    When running the same code on my pc I get a MsgBox saying:

    "After MoveDown 4:" followed by the content of the selected 5 lines.

    I thought about possible special characters in the cells. There are '#' and special german characters like ä,ö,ü but they don't seem to be a problem in my installation, and I have an english Office version installed. The customer has got a german installation, like probably mostly all of our other customers.

    So what can I do? Thanks for any helpful ideas.

    Greetings,  Maren

    Friday, March 21, 2014 9:52 AM
  • Hi MonaLisa ML,

    I can't reproduce your problem, so I can't give you a solid solution.

    I'm trying to involve senior engineers into your case, it'll take some time. We'll come back to you if there're some updates.

    Your patience will be appreciated. Thanks!

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 24, 2014 5:21 AM
  • Hi MonaLisa ML,

    >> Only for one customer it doesn't work, there is allways only the first row selected. <<

    If I understand correctly, this issue could not be reproducible in other machine with the same document and same Office version (Office 2013 Home & Business).  If so, I will suspect that it may be related to deployment environment.

    According to your scenario, I think the article as following may give you some help:

    VB6 based add-ins may fail to work in Office 2013



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 24, 2014 7:06 AM
  • Hello Jeffrey,

    I think your idea points in the right direction. I just got the latest version of the msaddndr.dll. I had VB6 SP6 installed but not the latest cummulativ update. Then I connected to the customer pc and copied the msaddndr.dll to the appropriate directory and registred it successfully. It wasn't on the machine before. Then we tried the programm, but unfortunately the problem still exists.

    I have to say, it's not an Add-In that's not working, but our program automates Word via the objects available in VB6. The programm either uses an existing instance of Word or creates a new one. Then a document from a database is opened and the programm uses different methods to manipulate the document and fill in values. When finished the document is closed again.

    As said before, everything works fine exept the MoveDown. And it is only one customer. The document in question is included in our the shipped database, it's a readonly template with form fields, so it is at least virtually the same as mine. To be on the safe side, I also saved the template from my pc and imported it on the customer pc, so that it really is the same document. And we compared the office versions of my test installation and the customers installation.

    Do you know of any other dlls or other files that could be missing in Office2013 or Windows7 64-bit?

    I don't know what else to try, thanks for any help,

    Greetings, Maren

    Monday, March 24, 2014 10:04 AM
  • Hello,

    another week has gone by and I'm no nearer to a solution, does anyone have another idea what to try or what else might be missing on the customers pc?

    Thanks for any help,     Maren

    Friday, March 28, 2014 8:30 AM
  • Hello,

    it's me again. Since the problem still exists, I would welcome any new idea how to resolve it.

    Thanks,  Maren

    Monday, April 7, 2014 9:27 AM
  • Hi Malen

    The method you're using reflects user actions, so in your place I might see what happens if you/the user holds down SHIFT and presses DownArrow. Can that select the lines the way your code should? If not, what happens?

    Something else I might try would be to rename the user's template then start Word. An old/damaged Normal template can cause really odd issues, and if the document is being created from it, that's even more likely.

    You might also try repairing the Office installation.

    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, April 12, 2014 3:51 PM
  • Hallo Cindy,

    thank you for your suggestions. I tried them all today. These are the results:

    1. Open the document, select the row containing the bookmark "Anlage7" and then press SHIFT and DownArrow: It worked fine and I got my row(s) selected as I expected it. Which is the same effect which I had when I tried my code in the document using the Macroeditor.

    Therefore my theory, that there is a difference between using the automation from inside Word and from outside Word.

    2. I renamed the normal.dotm and a new normal.dotm was created. It was a few bytes smaller, but the problem was still the same.

    3. We had already tried to repair the installation before, no positiv effect there too.

    Do you perhaps have any other ideas what to try? I would think it might be something in the environment.

    Perhaps a security option in the system or Office settings? A setting in a virus scanner (We tried disabling/deactivating it, but no effect)? Something in the .NET-environment?

    I still don't have other customers with this problem and I can't reproduce it either. But I see it when connecting to the client.

    Greetings,     Maren

    Monday, April 14, 2014 12:24 PM
  • Hi Maren

    I've been working with Word for over 20 years and I can't recall having encountered anything like this, before, so as with the others in this discussion, I'm grasping at straws...

    The next thing I'd try, in your place, would be to create a new profile for this user and see if things work that way...

    Mmm. Something else to consider would be whether there's some kind of add-in interfering. Since your program is automating Word, rather than running in-process, try starting an instance of Word in "safe mode" (hold down Ctrl, for instance). That will lock out everything that's not an installation default (including Normal template), then run your code against Word in safe mode. If that works, then you're looking for an add-in or something that's being loaded.

    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 14, 2014 2:40 PM
  • Hello Cindy,

    thanks again for your ideas. This time it's a bit more complicated to try them.

    Unfortunatly I'm not able to create a new profile on the clients pc, because they have external administrators doing these jobs and the users themselves don't have the administrative rights to do it. But I will ask the client to try this the next time the administrator is in the house.

    So the first thing I tried, was to try to use the Word Instance, that I had started in safe mode externally before, with my program. But it didn't work, I got error 429 'activeX component can't create object' and then the program automatically opens a new regular Word Instance.  Then I tried pressing Ctrl while the program created the new instance, but I didn't get the question about starting in safe mode and got a regular instance instead. Did I missunderstand your idea?

    But I had the idea about AddIn's too, because they sometimes interfere with our code. So we had checked that before and I didn't see any active AddIn's except some standard Microsoft AddIn's (I don't know, if I translate them correct, they are german: Chat contacts, date, phonenumbers, converter).

    I will answer again, when I have any new results. We want to try to setup a new pc and a new database (where we store the templates used to create the documents) and see if that brings any new insights. But because of the easter holidays coming that might take a while ;-)

    So long, happy easter, if you have any other ideas to try, let me know,

    greetings, Maren

    Tuesday, April 15, 2014 12:32 PM
  • Hello again,

    I still couldn't test the new profile.

    But I tested it with the new database, that we use as a default for all new installations, which includes the standard templates, that are working for all Word versions from Word 2000 to Word 2013. Unfortunately they didn't work for this customer. It's still the same problem. Can it be because these templates are in the old .dot-format, because they are used for older Word versions too? They are automatically opened in compatibility mode. That doesn't seem to be a general problem though, because I again tested it with different installations here and I can't reproduce the problem. The funny thing is, it's only this one function that doesn't seem to be working. All the other automation steps like open, close, save, copy, paste, find and replace seem to be working fine. Only the .MoveDown (wdLine, 4, wdExtend) doesn't work.

    For now I'm at my wits end. Our customer support has told me, he had heard of that problem sometimes before with some other customers, but there it always worked to generate the document repeatedly and after 2 or 3 tries it worked correct. I find that hard to believe, but in this case even that "straw" doesn't help.

    Do you have any other ideas?

    Thanks for your help, greetings,       Maren

    Tuesday, April 29, 2014 12:39 PM
  • Hi Maren

    The next thing I'd try would be to use other members of the wd Enumeration together with a different "Move" command, such as MoveRight. The thought being whether there's a problem just with going down, or with manipulating the Selection (emulating the Shift+Arrow keypresses).

    If there's generally a problem then there might be something installed on the machine's at the WINDOWS level that's interfering with these "keypresses" coming from outside Word. Possibly even an anti-virus software?

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, April 29, 2014 5:16 PM
  • Hello Cindy,

    sorry the answer took so long. I had some other work to do so couldn't press the matter. Because the testing of other 'moves' and 'other 'wd's in the regular program would be a bit complicated, I decided to write a small test program, where I only used a subset of the functionality of the 'real' program. I hoped it would show me, if the other 'moves' worked dirfferently.

    When testing it on the customers pc I was totally confused instead, because now not only the other 'moves' worked, but also the 'moveDown' worked correctly. Unfortunatly it still doesn't work in the 'real' program for this user. So I must have missed something when creating the test program, although I really copied the relevant snippets from the original code and pasted them to test code. The only thing I could think of was that in the test program I used the template directly and in the original program the template is copied first as new document and then manipulated.

    Next step will be to emulate this behavour too, but I need to find the time for it ;-)

    I hope I'm coming nearer to a solution (that will probably  be very simple, but I can't see it yet),

    when I finally find it, I will let you know,

    thanks and greetings,     Maren

    Monday, May 12, 2014 9:59 AM
  • Hi Maren

    Thanks for the interim report - interesting, that the actual user emulations are working in your test program! Nothing comes immediately to mind why this might be so on only the one installation...

    In your place, I might go back to the original program and substitute a move Right for the move Down, just to see if that works. If it does, I'd try putting a move Down immediately after the move Right. For some reason, the "cursor" may be in a place that's not allowing it to move down?

    Cindy Meister, VSTO/Word MVP, my blog

    Monday, May 12, 2014 1:34 PM