none
OPEN WORD DOC AS READ ONLY IN LATE BINDING RRS feed

  • Question

  • Hi there,

    I need to open a standard word document sheet (not a model), make all text insertions and so on, but I cannot save this new document over the standard one.

    I need to move for late binding, and I just don´t find the answer for this issue. Here is my code until open the standard word sheet to work with. In early binding, I just used the readonly=true, but already tried everything, nothing works. Please help me.

           Dim WA, WD, WS As Object
            WA = CreateObject("Word.Application")
            Dim WT1, WT2, WT3, WT4, WT5 As Word.Table
            Dim tableLocation As Word.Range
            Dim model_address As String
            Try
                model_address = Application.StartupPath & "\GTMS_MDL.doc"
                WA.Documents.Open(model_address)
                WD = WA.ActiveDocument
                WS = WA.Selection
    	........

    Tuesday, April 26, 2016 11:07 PM

All replies

  • Hi m-a-c-f,

    This forum is about the Visual Basic programming language, IDE, libraries, samples, and tools. (Not for VB6 questions), as your issue is more related to the Word development, we help you move it to the Word for Developers forum for better support.

    Thank you for your understanding.

    Best Regards,

    Albert Zhang

    Wednesday, April 27, 2016 5:29 AM
  • WA, WD,WS is Object (late binding) but WT1, WT2, WT3, WT4, WT5 is Word.Table
    and tableLocation is Word.Range (early binding).

    Why do you mix early and late bindings?


    Best regards, George


    Wednesday, April 27, 2016 12:14 PM
  • Hi,

    >>I need to open a standard word document sheet (not a model), make all text insertions and so on, but I cannot save this new document over the standard one.

    What did "model" mean?

    >>In early binding, I just used the readonly=true, but already tried everything, nothing works.

    If the readonly=true works for you in early binding, you can also use this parameter when you use the late binding.  

    In addition, the link below is helpful for leaning early binding and late binding:
    https://support.microsoft.com/en-sg/kb/245115

    Regards & Fei


    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, April 28, 2016 5:22 AM
    Moderator
  • Thanks,

    Changed to:

    Dim WA, WD, WS, WT1, WT2, WT3, WT4, WT5 As Object
    Seens to work better this way.

    Regards.

    Thursday, April 28, 2016 1:07 PM
  • What about  Dim tableLocation as Word.Range ?

    Best regards, George

    Thursday, April 28, 2016 1:09 PM
  • Hi George,

    Also moved to Object, working fine.

    Regards.

    Thursday, April 28, 2016 1:47 PM
  • Hummmmm.

    In previos early binding I was using this: it Works very fine.

    WD = WA.Documents.Open(model_address, [ReadOnly]:=True)
    Every time I change to this in late binding, I get an error, and the word document is not created.
    What I did? Once that the document is made over a standard sheet, with header and footer information, I moved around the corner.
    Even if the user choose to not save the just made document, due to the dialog at the end of procedure, once that it is not read only, the document stays in the screen, and if the user decide to close this document at later time, the Word asks him again if he (user) wants to save the document, but of course, it still the standard sheet, because it is not read only.
    So all the information in this existing not saved yet document, stays in the standard sheet now. When the user starts anew document, the standard sheet begins with previous information on it. I don´t know if I made myself clear?

    So, to tur around on this problem, I made this:

    WA.Selection.WholeStory()
    WA.Selection.Delete()
    These two above lines is not the desired solution, but clears every possible content on the standard sheet, avoiding that new document and erroneous information saved in previous sessions, remains in the new document, but of course, it still on the standart sheet.
    I am looking for one solution for this issue more than four months, and it seems that there is no solution for that.
    Regards.





    • Edited by m-a-c-f Thursday, April 28, 2016 1:55 PM
    Thursday, April 28, 2016 1:48 PM
  • Ok, what about Kudos to the people helping you?

    Best regards, George

    Thursday, April 28, 2016 2:47 PM
  • Sorry.

    Didnt follow you, what does it means "Kudos"

    Regards.

    Thursday, April 28, 2016 10:16 PM
  • Hi,

    >>Every time I change to this in late binding, I get an error, and the word document is not created.

    What's the error message you get? And what kind of document you were opening?

    The code below is that using late binding to open a document for your reference:

    Set wordApp = CreateObject("Word.Application")
    wordApp.Visible = True
    Set doc = wordApp.documents.Open("C:\test.docx", ReadOnly:=True)

    Please let me know whether it is helpful.

    Regards & Fei


    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.

    Tuesday, May 3, 2016 9:28 AM
    Moderator
  • Fei Xuei.

    Thanks, but didn´t worked!

    I give up!

    There is na error on document openning, and the word documment comes up empty.

    Thanks.

    Tuesday, May 3, 2016 10:02 PM
  • You should be using code like:

          Dim WA As Object, WD As Object, WS As Object
          Dim WT1 As Object, WT2 As Object, WT3 As Object, WT4 As Object, WT5 As Object
          Dim tableLocation  As Object, model_address As String
          WA = CreateObject("Word.Application")
          Try
              model_address = Application.StartupPath & "\GTMS_MDL.doc"
              WA.Documents.Open(model_address)
              WD = WA.ActiveDocument
              WS = WA.Selection

    Simply putting ' As Object' at the end of a line doesn't declare all the variables as Object; all except the last will be Variant. It would be easier to provide more specific help if you said exactly what it is you're trying to do. That said, since you're working with late binding, you might be interested in: http://www.techsupportforum.com/forums/f57/extracting-text-from-a-word-doc-into-excel-1116361.html
    and:
    http://www.msofficeforums.com/excel-programming/15845-adding-field-word-header-bookmark-table-excel.html#post44700

    The code in those post shows how one might automate a Word session from Excel, using late binding. The first processes a folder of documents, the second creates & populates a single document. Of course, you'd need to change the processing details for whatever your project is, but the code there should get you started.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, May 4, 2016 4:37 AM