I have a series of Excel spreadsheets, each with multiple worksheets.
I'd like to copy a certain column (user-defined) from each worksheet on the spreadsheet and paste it to a word doc, with the name of the worksheet above each copied column (the columns become tables when pasted to Word).
The contents of the clipboard seem to get lost when moving between the two applications. What would be the best way to transfer the data from one program to the other, retaining the cell-style layout?
What I have so far is:
VB Code:
Sub CopytoDocument() Dim cColumn As String Dim WordObj As Object Dim CellContents As String On Error Resume Next Err.Number = 0 Set WordObj = GetObject(, "Word.Application") If Err.Number = 429 Then Set WordObj = CreateObject("Word.Application") Err.Number = 0 End If cColumn = InputBox("Which column (indicate the letter)?") Columns(cColumn & ":" & cColumn).Select Selection.Copy 'CellContents = Selection WordObj.Visible = True WordObj.Documents.Add Selection.Paste End Sub




Reply With Quote