PinkUnicorn
New Member
- Joined
- Dec 12, 2017
- Messages
- 30
Hi, I wonder if anyone could help me please?
I've written the following to export the data in a spreadsheet to Word, and this works fine (albeit slowly!). However, it pastes into Word in a table form and because I then need to copy the Word information into a log in a separate system I need this to be in an unformatted text format.
Basically the excel document is being used to assess the risk of something, and I need the details of the risk assessment and the outcome to be able to be pasted into a log. We can't do this directly from excel as the cells will not paste into the log without copying and pasting each one individually. So the workaround I was looking at was exporting from excel into Word in an unformatted format, then copy that text and paste into the log. Long winded, I know, but the best I can come up with.
Alternatively we could export to a text file which might be easier?
So - the code I am using is below and if anyone can tell me where I am going wrong that would be so fantastic (I have already spent hours trying to work this out myself and have now admitted that I really have no idea what I am doing!!) I have tried to change "newObj.Range.Paste" to "newObj.Range.PasteSpecial Unformatted Text" but that just gets to opening Word and not going any further (so no paste taking place).
Happy to hear any alternative suggestions if there are thoughts on a better workaround to my idea too.
Thanks so much
Sub export_excel_to_word()
Set obj = CreateObject("Word.Application")
obj.Visible = True
Set newObj = obj.Documents.Add
ActiveSheet.UsedRange.Copy
newObj.Range.Paste
Application.CutCopyMode = False
obj.Activate
newObj.SaveAs FileName:=Application.ActiveWorkbook.Path & "" & ActiveSheet.Name
End Sub
I've written the following to export the data in a spreadsheet to Word, and this works fine (albeit slowly!). However, it pastes into Word in a table form and because I then need to copy the Word information into a log in a separate system I need this to be in an unformatted text format.
Basically the excel document is being used to assess the risk of something, and I need the details of the risk assessment and the outcome to be able to be pasted into a log. We can't do this directly from excel as the cells will not paste into the log without copying and pasting each one individually. So the workaround I was looking at was exporting from excel into Word in an unformatted format, then copy that text and paste into the log. Long winded, I know, but the best I can come up with.
Alternatively we could export to a text file which might be easier?
So - the code I am using is below and if anyone can tell me where I am going wrong that would be so fantastic (I have already spent hours trying to work this out myself and have now admitted that I really have no idea what I am doing!!) I have tried to change "newObj.Range.Paste" to "newObj.Range.PasteSpecial Unformatted Text" but that just gets to opening Word and not going any further (so no paste taking place).
Happy to hear any alternative suggestions if there are thoughts on a better workaround to my idea too.
Thanks so much
Sub export_excel_to_word()
Set obj = CreateObject("Word.Application")
obj.Visible = True
Set newObj = obj.Documents.Add
ActiveSheet.UsedRange.Copy
newObj.Range.Paste
Application.CutCopyMode = False
obj.Activate
newObj.SaveAs FileName:=Application.ActiveWorkbook.Path & "" & ActiveSheet.Name
End Sub