Muttdog117
New Member
- Joined
- Sep 10, 2009
- Messages
- 33
What is the best way to import a word doc into a single cell? I currently have a script in Excel that opens a word doc, edits it and then copies to the clipboard. That part works great. The problem I am having is that I want to paste the data into a single cell in Excel. The Word doc is very long and has a lot of line breaks in it. When Excel imports the file, it places each line into a new cell in the same column. I need all of it to be in one cell.
Private Sub CommandButton2_Click()
Dim objWord
Dim objDoc
Dim objRange
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\users\Stan Laptop\My Documents\NewProductTemplateFile.docx")
objWord.Visible = True
Set objRange = objDoc.Bookmarks("Title").Range
objRange.InsertAfter Worksheets("Sheet2").Range("D2")
Set objRange = objDoc.Bookmarks("URL1").Range
If Worksheets("Sheet2").Range("R2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image1").Range
objRange.InsertAfter Worksheets("Sheet2").Range("R2")
End If
Set objRange = objDoc.Bookmarks("URL2").Range
If Worksheets("Sheet2").Range("R2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image2").Range
objRange.InsertAfter Worksheets("Sheet2").Range("R2")
End If
Set objRange = objDoc.Bookmarks("URL3").Range
If Worksheets("Sheet2").Range("S2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image3").Range
objRange.InsertAfter Worksheets("Sheet2").Range("S2")
End If
Set objRange = objDoc.Bookmarks("URL4").Range
If Worksheets("Sheet2").Range("S2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image4").Range
objRange.InsertAfter Worksheets("Sheet2").Range("S2")
End If
Set objRange = objDoc.Bookmarks("URL5").Range
If Worksheets("Sheet2").Range("T2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image5").Range
objRange.InsertAfter Worksheets("Sheet2").Range("T2")
End If
Set objRange = objDoc.Bookmarks("URL6").Range
If Worksheets("Sheet2").Range("T2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image6").Range
objRange.InsertAfter Worksheets("Sheet2").Range("T2")
End If
Set objRange = objDoc.Bookmarks("URL7").Range
If Worksheets("Sheet2").Range("U2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image7").Range
objRange.InsertAfter Worksheets("Sheet2").Range("U2")
End If
Set objRange = objDoc.Bookmarks("URL8").Range
If Worksheets("Sheet2").Range("U2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image8").Range
objRange.InsertAfter Worksheets("Sheet2").Range("U2")
End If
Set objRange = objDoc.Bookmarks("URL9").Range
If Worksheets("Sheet2").Range("V2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image9").Range
objRange.InsertAfter Worksheets("Sheet2").Range("V2")
End If
Set objRange = objDoc.Bookmarks("URL10").Range
If Worksheets("Sheet2").Range("V2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image10").Range
objRange.InsertAfter Worksheets("Sheet2").Range("V2")
End If
Set objRange = objDoc.Bookmarks("URL11").Range
If Worksheets("Sheet2").Range("W2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image11").Range
objRange.InsertAfter Worksheets("Sheet2").Range("W2")
End If
Set objRange = objDoc.Bookmarks("URL12").Range
If Worksheets("Sheet2").Range("W2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image12").Range
objRange.InsertAfter Worksheets("Sheet2").Range("W2")
End If
Set objRange = objDoc.Bookmarks("URL13").Range
If Worksheets("Sheet2").Range("X2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image13").Range
objRange.InsertAfter Worksheets("Sheet2").Range("X2")
End If
Set objRange = objDoc.Bookmarks("URL14").Range
If Worksheets("Sheet2").Range("X2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image14").Range
objRange.InsertAfter Worksheets("Sheet2").Range("X2")
End If
Set objRange = objDoc.Bookmarks("URL15").Range
If Worksheets("Sheet2").Range("Y2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image15").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Y2")
End If
Set objRange = objDoc.Bookmarks("URL16").Range
If Worksheets("Sheet2").Range("Y2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image16").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Y2")
End If
Set objRange = objDoc.Bookmarks("URL17").Range
If Worksheets("Sheet2").Range("Z2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image17").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Z2")
End If
Set objRange = objDoc.Bookmarks("URL18").Range
If Worksheets("Sheet2").Range("Z2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image18").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Z2")
End If
Set objRange = objDoc.Bookmarks("URL19").Range
If Worksheets("Sheet2").Range("AA2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image19").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AA2")
End If
Set objRange = objDoc.Bookmarks("URL20").Range
If Worksheets("Sheet2").Range("AA2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image20").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AA2")
End If
Set objRange = objDoc.Bookmarks("URL21").Range
If Worksheets("Sheet2").Range("AB2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image21").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AB2")
End If
Set objRange = objDoc.Bookmarks("URL22").Range
If Worksheets("Sheet2").Range("AB2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image22").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AB2")
End If
Set objRange = objDoc.Bookmarks("URL23").Range
If Worksheets("Sheet2").Range("AC2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image23").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AC2")
End If
Set objRange = objDoc.Bookmarks("URL24").Range
If Worksheets("Sheet2").Range("AC2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image24").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AC2")
End If
Set objRange = objDoc.Bookmarks("VideoHTML").Range
If Worksheets("Sheet2").Range("AV2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Videolink1").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AV2")
Set objRange = objDoc.Bookmarks("Videolink2").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AV2")
End If
Set objRange = objDoc.Bookmarks("Description").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AI2")
Set objRange = objDoc.Bookmarks("BulletPoint1").Range
If Worksheets("Sheet2").Range("AJ2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData1").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AJ2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint2").Range
If Worksheets("Sheet2").Range("AK2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData2").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AK2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint3").Range
If Worksheets("Sheet2").Range("AL2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData3").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AL2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint4").Range
If Worksheets("Sheet2").Range("AM2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData4").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AM2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint5").Range
If Worksheets("Sheet2").Range("AN2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData5").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AN2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint6").Range
If Worksheets("Sheet2").Range("AO2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData6").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AO2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint7").Range
If Worksheets("Sheet2").Range("AP2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData7").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AP2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint8").Range
If Worksheets("Sheet2").Range("AQ2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData8").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AQ2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint9").Range
If Worksheets("Sheet2").Range("AR2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData9").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AR2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint10").Range
If Worksheets("Sheet2").Range("AS2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData10").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AS2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint11").Range
If Worksheets("Sheet2").Range("AT2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData11").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AT2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint12").Range
If Worksheets("Sheet2").Range("AU2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData12").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AU2")
End If
'Everything up to this point works fine. I don't know how to get this file into a single cell in Excel:
objDoc.Range.Select
objDoc.Range.Copy
Worksheets("Sheet4").Range("G2").Select
'Range("G2").Select
'SendKeys "{F2}"
'ActiveSheet.Paste
T
Private Sub CommandButton2_Click()
Dim objWord
Dim objDoc
Dim objRange
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\users\Stan Laptop\My Documents\NewProductTemplateFile.docx")
objWord.Visible = True
Set objRange = objDoc.Bookmarks("Title").Range
objRange.InsertAfter Worksheets("Sheet2").Range("D2")
Set objRange = objDoc.Bookmarks("URL1").Range
If Worksheets("Sheet2").Range("R2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image1").Range
objRange.InsertAfter Worksheets("Sheet2").Range("R2")
End If
Set objRange = objDoc.Bookmarks("URL2").Range
If Worksheets("Sheet2").Range("R2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image2").Range
objRange.InsertAfter Worksheets("Sheet2").Range("R2")
End If
Set objRange = objDoc.Bookmarks("URL3").Range
If Worksheets("Sheet2").Range("S2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image3").Range
objRange.InsertAfter Worksheets("Sheet2").Range("S2")
End If
Set objRange = objDoc.Bookmarks("URL4").Range
If Worksheets("Sheet2").Range("S2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image4").Range
objRange.InsertAfter Worksheets("Sheet2").Range("S2")
End If
Set objRange = objDoc.Bookmarks("URL5").Range
If Worksheets("Sheet2").Range("T2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image5").Range
objRange.InsertAfter Worksheets("Sheet2").Range("T2")
End If
Set objRange = objDoc.Bookmarks("URL6").Range
If Worksheets("Sheet2").Range("T2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image6").Range
objRange.InsertAfter Worksheets("Sheet2").Range("T2")
End If
Set objRange = objDoc.Bookmarks("URL7").Range
If Worksheets("Sheet2").Range("U2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image7").Range
objRange.InsertAfter Worksheets("Sheet2").Range("U2")
End If
Set objRange = objDoc.Bookmarks("URL8").Range
If Worksheets("Sheet2").Range("U2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image8").Range
objRange.InsertAfter Worksheets("Sheet2").Range("U2")
End If
Set objRange = objDoc.Bookmarks("URL9").Range
If Worksheets("Sheet2").Range("V2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image9").Range
objRange.InsertAfter Worksheets("Sheet2").Range("V2")
End If
Set objRange = objDoc.Bookmarks("URL10").Range
If Worksheets("Sheet2").Range("V2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image10").Range
objRange.InsertAfter Worksheets("Sheet2").Range("V2")
End If
Set objRange = objDoc.Bookmarks("URL11").Range
If Worksheets("Sheet2").Range("W2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image11").Range
objRange.InsertAfter Worksheets("Sheet2").Range("W2")
End If
Set objRange = objDoc.Bookmarks("URL12").Range
If Worksheets("Sheet2").Range("W2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image12").Range
objRange.InsertAfter Worksheets("Sheet2").Range("W2")
End If
Set objRange = objDoc.Bookmarks("URL13").Range
If Worksheets("Sheet2").Range("X2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image13").Range
objRange.InsertAfter Worksheets("Sheet2").Range("X2")
End If
Set objRange = objDoc.Bookmarks("URL14").Range
If Worksheets("Sheet2").Range("X2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image14").Range
objRange.InsertAfter Worksheets("Sheet2").Range("X2")
End If
Set objRange = objDoc.Bookmarks("URL15").Range
If Worksheets("Sheet2").Range("Y2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image15").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Y2")
End If
Set objRange = objDoc.Bookmarks("URL16").Range
If Worksheets("Sheet2").Range("Y2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image16").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Y2")
End If
Set objRange = objDoc.Bookmarks("URL17").Range
If Worksheets("Sheet2").Range("Z2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image17").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Z2")
End If
Set objRange = objDoc.Bookmarks("URL18").Range
If Worksheets("Sheet2").Range("Z2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image18").Range
objRange.InsertAfter Worksheets("Sheet2").Range("Z2")
End If
Set objRange = objDoc.Bookmarks("URL19").Range
If Worksheets("Sheet2").Range("AA2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image19").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AA2")
End If
Set objRange = objDoc.Bookmarks("URL20").Range
If Worksheets("Sheet2").Range("AA2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image20").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AA2")
End If
Set objRange = objDoc.Bookmarks("URL21").Range
If Worksheets("Sheet2").Range("AB2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image21").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AB2")
End If
Set objRange = objDoc.Bookmarks("URL22").Range
If Worksheets("Sheet2").Range("AB2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image22").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AB2")
End If
Set objRange = objDoc.Bookmarks("URL23").Range
If Worksheets("Sheet2").Range("AC2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image23").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AC2")
End If
Set objRange = objDoc.Bookmarks("URL24").Range
If Worksheets("Sheet2").Range("AC2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Image24").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AC2")
End If
Set objRange = objDoc.Bookmarks("VideoHTML").Range
If Worksheets("Sheet2").Range("AV2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("Videolink1").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AV2")
Set objRange = objDoc.Bookmarks("Videolink2").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AV2")
End If
Set objRange = objDoc.Bookmarks("Description").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AI2")
Set objRange = objDoc.Bookmarks("BulletPoint1").Range
If Worksheets("Sheet2").Range("AJ2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData1").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AJ2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint2").Range
If Worksheets("Sheet2").Range("AK2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData2").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AK2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint3").Range
If Worksheets("Sheet2").Range("AL2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData3").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AL2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint4").Range
If Worksheets("Sheet2").Range("AM2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData4").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AM2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint5").Range
If Worksheets("Sheet2").Range("AN2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData5").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AN2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint6").Range
If Worksheets("Sheet2").Range("AO2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData6").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AO2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint7").Range
If Worksheets("Sheet2").Range("AP2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData7").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AP2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint8").Range
If Worksheets("Sheet2").Range("AQ2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData8").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AQ2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint9").Range
If Worksheets("Sheet2").Range("AR2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData9").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AR2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint10").Range
If Worksheets("Sheet2").Range("AS2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData10").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AS2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint11").Range
If Worksheets("Sheet2").Range("AT2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData11").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AT2")
End If
Set objRange = objDoc.Bookmarks("BulletPoint12").Range
If Worksheets("Sheet2").Range("AU2").Value = "" Then
objRange.Delete
Else
Set objRange = objDoc.Bookmarks("BulletData12").Range
objRange.InsertAfter Worksheets("Sheet2").Range("AU2")
End If
'Everything up to this point works fine. I don't know how to get this file into a single cell in Excel:
objDoc.Range.Select
objDoc.Range.Copy
Worksheets("Sheet4").Range("G2").Select
'Range("G2").Select
'SendKeys "{F2}"
'ActiveSheet.Paste
T