Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 08-20-2018, 02:42 AM
macropod's Avatar
macropod macropod is offline repeat header rows after VBA paste Windows 7 64bit repeat header rows after VBA paste Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Your code doesn't say what 'HeadingFormat = True' applies to.
Try:
Code:
Sub ExcelDataToWord()
Dim objWord As Object, objDoc As Object
Dim strFolder As String, strName As String
Dim ws As Worksheet
Dim lngLastRow As Long
On Error GoTo Errorcatch
'------------browse---------------
'--------------------defaulting folder------------------------
With Application.FileDialog(msoFileDialogFilePicker)
  .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---------------

Set ws = ThisWorkbook.Sheets("RISKS")
lngLastRow = ws.Range("A65535").End(xlUp).Row
Set objWord = CreateObject("Word.Application")
ws.Range("A4" & ":H" & lngLastRow).Copy

'open the word doc
'objWord.Documents.Open "C:\Users\name\Desktop\RAMS AUTOMATION\Import table test.docx" 'change as required
With objWord
  .Visible = True
  Set objDoc = .Documents.Open(strFolder)
  'pastes the value of cell at the bookmark
  With objDoc.Bookmarks("RISKS").Range
    .Characters.Last.Next.PasteAppendTable
    .Tables(1).Rows(1).HeadingFormat = True
  End With
  .Activate
End With
Set objWord = Nothing: Set objDoc = Nothing
'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
Note the other modifications I've made to your code.

PS: When posting code, please ensure it's properly formatted - yours didn't even have line breaks.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
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 02:19 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