Microsoft
Software
Hardware
Network
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.applica
tion")
Set NewSht = ThisWorkbook.Sheets.Add
ActiveSheet.Name = "dummy"
Worksheets("sheet1").Activ
ate 'Activate the worksheet
'Select the range of cells to copy
'Worksheets("sheet1").Rang
e("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.Sele
ct
Set obj = CreateObject("Word.Applica
tion.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.OperatingSyst
em 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).A
utoFormat Format:=wdTableFormatGrid1
newDoc.SaveAs Filename:="C:\TestDoc33a.d
oc" 'Save the file
'obj.Quit 'Quit Word
Set obj = Nothing 'Release object
Application.DisplayAlerts = False
Sheets("dummy").Delete
Application.DisplayAlerts = True
End Sub
Random Solutions
DevExpress XtraTreeList - tree structure
Setup POP3 on Exchange 2007 / SBS 2008 Server
Simple T-SQL question...
Sharepoint Backup
Why wont a hp laptop power up?
Transfer data from Access to Excel
Sql Non Disctinct possibility ?
Server rebooting with Error code Error code 000000d1, parameter1 00000004, parameter2 d0000009, parameter3 00000000, parameter4 f737bb85.
Startup the server remotely,
Handling Images in Silverlight