Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-11-2020, 03:32 PM
Adrian Radoi Adrian Radoi is offline Text, then table, then more text and table and final text Windows 10 Text, then table, then more text and table and final text Office 2016
Novice
Text, then table, then more text and table and final text
 
Join Date: Mar 2020
Posts: 3
Adrian Radoi is on a distinguished road
Exclamation Text, then table, then more text and table and final text

I am trying to build a word document from excel. basically the excel table just takes values and transfers them into the word document.

Currently I created part of it but somehow the cursor gets stuck at the first table and the second table is inserted in the first one.

The format I am trying to look for is.

Text.
Table
Text
Table


Ending Text

HEre is my code so far.

Code:
Option Explicit

 

Sub CreateBasicWordReport()

 

    Dim wdApp As Word.Application

    Dim objRange

    Dim objDoc

    Dim Cell

    Dim NewRange

 

    Set wdApp = New Word.Application

   

    

    With wdApp

         .Visible = True

         .Activate

        

         .Documents.Add

               

                With .Selection

                     .ParagraphFormat.Alignment = wdAlignParagraphCenter

                     .BoldRun

                     .Font.Size = 11

                     .TypeText "Letter to Proceed with Transfer"

                     .TypeParagraph

                     .Font.Size = 11

                     .TypeText "Determination of Transfer Value and Request for Transfer"

                     .TypeParagraph

                     .TypeParagraph

                     .TypeParagraph

                    

                     .ParagraphFormat.Alignment = wdAlignParagraphLeft

                    

                

                End With

               

          

                

        End With

     

      Set objRange = wdApp.ActiveDocument.Range

      objRange.Collapse Direction:=wdCollapseEnd

     

      wdApp.ActiveDocument.Tables.Add objRange, 4, 2

     

      With wdApp.ActiveDocument.Tables(1).Cell(1, 1).Range

           

         .Bold = False

         .Text = "Date"

           

      End With

     

      With wdApp.ActiveDocument.Tables(1).Cell(2, 1).Range

          

         .Bold = False

         .Text = "Exportin"

           

      End With

     

      With wdApp.ActiveDocument.Tables(1).Cell(3, 1).Range

          

         .Bold = False

         .Text = "Importing"

           

      End With

     

      With wdApp.ActiveDocument.Tables(1).Cell(4, 1).Range

          

         .Bold = False

         .Text = "Re"

           

      End With

     

      With wdApp.ActiveDocument.Tables(1).Cell(1, 2).Range

          

         .Bold = False

         .Text = "Re"

           

      End With

     

      With wdApp.ActiveDocument.Tables(1).Cell(2, 2).Range

          

         .Bold = False

         .Text = "Re"

           

      End With

     

      With wdApp.ActiveDocument.Tables(1).Cell(3, 2).Range

          

         .Bold = False

         .Text = "Re"

           

      End With

     

      

      With wdApp.ActiveDocument.Tables(1).Cell(4, 2).Range

          

         .Bold = False

         .Text = "Re"

           

      End With

     

      

      objRange.Collapse Direction:=wdCollapseEnd

     

      wdApp.ActiveDocument.Range.InsertAfter "_____________________________________________________________________________________"

      wdApp.ActiveDocument.Range.InsertAfter "Part 1"

     

      wdApp.ActiveDocument.Bookmarks.Exists ("\EndOfDoc")

     

      

     ' wdApp.ActiveDocument.

      'Set NewRange = ActiveDocument.Content

      'NewRange.Collapse Direction:=wdCollapseEnd

    
      'wdApp.ActiveDocument.Tables.Add (

      'wdApp.ActiveDocument.Range.Collapse Direction:=wdCollapseEnd
      

      

      

      'objRange.Collapse Direction:=wdCollapseEnd

     

      'wdApp.ActiveDocument.Paragraphs.Add.Range.Text = "FGHFHDFg"

     

      'wdApp.ActiveDocument.Tables.Add NewRange, 4, 2

     

      'Set objTable = wdApp.ActiveDocument.Tabl

      'objTable.Cell(1, 1).Range.Text = "WOO"

     

      'wdApp.Documents.Add.Tables.Add wdApp.ActiveDocument.Range, 5,

 

End Sub
Reply With Quote
  #2  
Old 03-11-2020, 05:12 PM
Guessed's Avatar
Guessed Guessed is offline Text, then table, then more text and table and final text Windows 10 Text, then table, then more text and table and final text Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You should create the basic layout as a Word template so that when you create the initial document, it already contains the standard content and formatting.

Set objDoc = .Documents.Add(sPathToTemplate)

If your template already contained all the elements your code creates then the rest of the code you showed is actually not needed. You would then use code to bring in the Excel content itself.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-11-2020, 08:34 PM
macropod's Avatar
macropod macropod is offline Text, then table, then more text and table and final text Windows 7 64bit Text, then table, then more text and table and final text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: excel - Word VBA Text then table then text then table - Stack Overflow
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 03-11-2020, 08:54 PM
Adrian Radoi Adrian Radoi is offline Text, then table, then more text and table and final text Windows 10 Text, then table, then more text and table and final text Office 2016
Novice
Text, then table, then more text and table and final text
 
Join Date: Mar 2020
Posts: 3
Adrian Radoi is on a distinguished road
Default

My template is not static. Doesn't that change things?

There should be an 3 if conditions that change the output the text at the middle and end of the document.
Reply With Quote
  #5  
Old 03-11-2020, 09:00 PM
macropod's Avatar
macropod macropod is offline Text, then table, then more text and table and final text Windows 7 64bit Text, then table, then more text and table and final text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I have already responded to that in your cross-post...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 03-11-2020, 09:07 PM
Adrian Radoi Adrian Radoi is offline Text, then table, then more text and table and final text Windows 10 Text, then table, then more text and table and final text Office 2016
Novice
Text, then table, then more text and table and final text
 
Join Date: Mar 2020
Posts: 3
Adrian Radoi is on a distinguished road
Default

I appologize i am quite new you are correct.

Add or delete bookmarks in a Word document or Outlook message - Office Support

Would I proceed to add bookmarks in this manner?
Reply With Quote
  #7  
Old 03-11-2020, 10:12 PM
macropod's Avatar
macropod macropod is offline Text, then table, then more text and table and final text Windows 7 64bit Text, then table, then more text and table and final text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Yes, that's how you might create one for your template, but the GUI approach for accessing them isn't what you'd use in VBA. There are many VBA examples here showing how you'd do that. Do a search on: UpdateBookmark
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Text, then table, then more text and table and final text Scan text for specific word/text and list in table fietstasss Word VBA 1 01-15-2018 02:05 PM
How to prevent the text goes down with setting text around the table in MS Word? tesicg Word Tables 1 06-07-2016 08:46 AM
Text, then table, then more text and table and final text VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color jc491 Word VBA 8 09-30-2015 06:10 AM
VBA Search Table for Text/Select Text/Insert Hyperlink sldrellich Word VBA 3 03-24-2015 01:09 PM
Convert Text To Table: Separate text at (Other)? tinfanide Word VBA 2 01-12-2015 05:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft