Results 1 to 11 of 11

Thread: MS Word

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    MS Word

    Hi,
    In a VB app i am joining .doc into a master document.when i insert the docs the master the formatting changes sometimes is it possible to insert without affectting the formatting.

    adhi

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Word

    Post your code for inserting.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word

    VB Code:
    1. Public Sub DocOpen(ByVal sFile As String, Optional ViewOnly As Variant, Optional AddToRecentFile As Variant)
    2.     Dim bViewOnly As Boolean
    3.     Dim bAddToRecentFile As Boolean
    4.    
    5.  On Error GoTo ErrorHandler
    6.  
    7.     bViewOnly = False
    8.     bAddToRecentFile = False
    9.     If Not IsMissing(ViewOnly) Then
    10.         bViewOnly = ViewOnly
    11.     End If
    12.     If Not IsMissing(AddToRecentFile) Then
    13.         bAddToRecentFile = AddToRecentFile
    14.     End If
    15.     Set m_WordDoc = m_WordApp.Documents.Open(sFile, , bViewOnly, bAddToRecentFile)
    16.     Set m_WordRange = m_WordDoc.Range
    17.     If bViewOnly Then
    18.         m_WordApp.ActiveDocument.Protect wdAllowOnlyComments
    19.     End If
    20.    
    21. Exit Sub

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Word

    So your saying that this line is adding a document to the documents collection and changing the formatting?
    VB Code:
    1. Set m_WordDoc = m_WordApp.Documents.Open(sFile, , bViewOnly, bAddToRecentFile)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word

    sorry i sent you the wrong code.
    VB Code:
    1. Public Sub DocAdd(ByVal sDocfile As String)
    2.     Dim lEndDoc As Long
    3.    
    4.     lEndDoc = m_WordRange.End
    5.     With m_WordApp.Selection
    6.         .Move unit:=wdCharacter, Count:=lEndDoc
    7.         .InsertBreak wdSectionBreakNextPage
    8.         .Collapse Direction:=wdCollapseEnd
    9.         .InsertFile sDocfile, , , True
    10.         Set m_WordRange = m_WordDoc.Range(lEndDoc, m_WordDoc.Range.End)
    11.     End With
    12.    
    13. End Sub

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Word

    What if you did a copy/paste? It would then retain the formatting/coloring etc. but then you would have to code in the opening and selection and copying of the to be pasted document.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word

    Yeah...instead Of Inserting File..i May Copy And Paste...that Might Work...let Me Try.

    Thanks

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word

    I tried doing it...i dont exactly to do it..

    need help

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Word

    Post your code and what is going on.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word

    You suggested ..that instead of inserting file to the master document, to copy/paste. But i dont know exactly how to do it. i tried opening the doc to copy the contents for copy paste...but i dont know how to do it.

    the code i posted earlier is the one i used to insert docs into the master document.

    adhi

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MS Word

    You open another document and select the entire document. Then paste it into the current position in your master document.

    Just the basics ...

    VB Code:
    1. 'Select the entire doc
    2. Dim oDoc As Word.Document
    3. Set oDoc = m_WordApp.Documents.Open("C:\SomeOtherFile.doc")
    4. oDoc.Activate
    5. m_WordApp.Selection.WholeStory
    6. m_WordApp.Selection.CopyFormat 'Or Selection.Copy
    7. m_WordApp.Documents("MasterDocName").Activate
    8. m_WordApp.Paste' Or PasteFormat
    9.  
    10. 'Close the other document, etc.
    11. oDoc.Close False
    12. Set oDoc = Nothing
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width