Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 08-20-2018, 01:16 AM
Homegrownandy Homegrownandy is offline repeat header rows after VBA paste Windows 10 repeat header rows after VBA paste Office 2016
Novice
repeat header rows after VBA paste
 
Join Date: Jul 2018
Posts: 14
Homegrownandy is on a distinguished road
Default

Code:
Sub ExcelDataToWord()
Dim objWord As Object
Dim ws As Worksheet
Dim lngLastRow As Long
On Error GoTo Errorcatch
lngLastRow = Sheets("RISKS").Range("A65535").End(xlUp).Row
Set ws = ThisWorkbook.Sheets("RISKS")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
'Optimize Code
Application.ScreenUpdating = False
Application.EnableEvents = False
ws.Range("A4" & ":H" & lngLastRow).Copy
'------------browse---------------
Dim fileExplorer As FileDialog
Set fileExplorer = Application.FileDialog(msoFileDialogFilePicker)
'--------------------defaulting folder------------------------
With fileExplorer
  .Title = "Select a Folder"
  .AllowMultiSelect = False
  .ButtonName = "Select"
  .InitialView = msoFileDialogViewList
  .InitialFileName = "\\server\general\RAMS\RAM_RAMS"
  If Right(strName, 1) <> "\" Then
    strFolder = strFolder
  End If
  If .Show <> -1 Then
    Exit Sub
  Else
    strFolder = .SelectedItems(1)
  End If
 End With
'--------------------defaulting folder------------------------
'------------browse---------------
'open the word doc
'objWord.Documents.Open "C:\Users\name\Desktop\RAMS AUTOMATION\Import table test.docx" 'change as required
objWord.Documents.Open FileName:=strFolder  'pastes the value of cell at the bookmark
With objWord.ActiveDocument.Bookmarks("RISKS").Range.Characters.Last.Next.PasteAppendTable
  HeadingFormat = True
End With
'Optimize Code
Set objWord = Nothing
Application.ScreenUpdating = True
Application.EnableEvents = True
'Clear The Clipboard
Application.CutCopyMode = False
Exit Sub
Errorcatch:
Debug.Assert False
MsgBox Err.Description
' This is temporary, if you leave it in it will go into an endless loop so do not forget to remove
Resume
End Sub
I'm not sute if you can read the code ive put in here as it's putting it in a small code box. I can paste it all without that if you need.

Its taking data from access in an excel table (only way to avoid formatting errors when using the paste append) and then putting it into word.

The repeating headers isn't its just a nice to have htat should be working.

Thanks, Andy.

Last edited by macropod; 08-20-2018 at 02:25 AM. Reason: Added code formatting
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste an image and have it repeat elsewhere in doc automatically sryan Word VBA 1 07-06-2015 01:39 PM
repeat header rows after VBA paste Repeat header of a table, what about captions ? Yankel Word Tables 3 08-01-2014 05:18 PM
Repeat rows--NOT markg2 Excel 0 03-01-2014 11:21 AM
repeat selected table row as header eNGiNe Word 2 10-15-2013 11:16 PM
repeat header rows after VBA paste how to repeat row in header gsrikanth Excel 10 06-28-2012 02:31 AM

Other Forums: Access Forums

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


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