|
Question : Need a MACRO to export an excel spreadsheet to word but only wish for certain columns in spreadsheet to be exported.
|
|
Hi here is my problem for creating a macro to do this:
i have a Spreadsheet: Column 1 Column 2 Column3 Column4 Column5 Column6 Column7 Column8
I want the above spreadsheet to be exported to Word in a new document like this: Column 1 Column 2 Column3 Column7 Column8
I need Column 1 then to be renamed as Column A and Column 2 renamed as Column B - then I also need all the data in Column 1 to be appended with "XXX" at the beginning and the same for Column 2
|
|
Answer : Need a MACRO to export an excel spreadsheet to word but only wish for certain columns in spreadsheet to be exported.
|
|
Had just a few spare minutes:
Sub PasteTableToWord() Set obj = CreateObject("word.application") Set NewSht = ThisWorkbook.Sheets.Add ActiveSheet.Name = "dummy"
Worksheets("sheet1").Activate 'Activate the worksheet 'Select the range of cells to copy 'Worksheets("sheet1").Range("A:A,B:B,C:C,G:G,H:H").Copy Worksheets("sheet1").Range("A:A,B:B,C:C,G:G,H:H").Select Selection.Copy Sheets("dummy").Select Range("A1").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Selection.Copy ActiveSheet.UsedRange.Select Set obj = CreateObject("Word.Application.9") 'Create a word object obj.Visible = True 'Make Word visible Set newDoc = obj.Documents.Add 'Create a new file. 'Determine if Microsoft Excel is running on the Macintosh or Windows. If (Application.OperatingSystem Like "*Mac*") Then AppActivate "Microsoft word" obj.Selection.PasteSpecial 'Paste data into Word Else 'If Windows NT/95/3.x - paste data into Word obj.Selection.PasteSpecial End If 'Format table 'obj.Selection.Tables(1).AutoFormat Format:=wdTableFormatGrid1 newDoc.SaveAs Filename:="C:\TestDoc33a.doc" 'Save the file 'obj.Quit 'Quit Word Set obj = Nothing 'Release object Application.DisplayAlerts = False Sheets("dummy").Delete Application.DisplayAlerts = True End Sub
|
|
|
|