-
Solved: copy from excel to word unmerged table
hello
I try to copy paste an excel table to word.In excel I do not have merged cells. but wen I pasted in word some cells become merged (special cells from headers). What can I do to avoid this situation?
[vba]
With ActiveWorkbook.Worksheets(shName)
.Range(Cells(rand, 1).Address, Cells(l_row, coloana).Address).Copy
wordDoc.Bookmarks("Tabel").Range.Paste
End With
[/vba]
I try also this (no success):
[vba]
wordDoc.Tables(wordDoc.Tables.Count).Select
Selection.MergeCells = False
[/vba]
-
I putted like this:
[vba]
With ActiveWorkbook.Worksheets(shName)
.Range(Cells(rand, 1).Address, Cells(l_row, coloana).Address).Columns.AutoFit
.Range(Cells(rand, 1).Address, Cells(l_row, coloana).Address).Copy
wordDoc.Bookmarks("Tabel").Range.Paste
End With
[/vba]
First will autofit the columns, copy then will paste the table.
-
[VBA]
Sub M_snb()
with createobject("Word.Document")
.Fields.Add Paragraphs(1).Range, , "includetext G:\\OF\\adressen.xls A1:K10", False
.Fields.Update
end with
End Sub
[/VBA]
-
Hi snb
I will use .Columns.Autofit
then I will not gone have problems.
What do you think?
ps.Your solution is give me error 5825 (Object has been deleted)
-
You have to adapt the path and filename of course......
[VBA]
Sub M_snb()
With createobject("Word.Document")
.Fields.Add .Paragraphs(1).Range, , "includetext G:\\OF\\adressen.xls A1:K10", False
.Fields.Update
End With
End Sub
[/VBA]
-
ok. What I am doing wrong (via Bookmarks already created in an created word file):
[vba]
With ThisWorkbook.Worksheets(shName)
.Range(Cells(rand, 1).Address, Cells(l_row, coloana).Address).Columns.AutoFit
.Range(Cells(rand, 1).Address, Cells(l_row, coloana).Address).Copy
With wordDoc
.Fields.Add .Bookmarks("Tabel").Range, , ThisWorkbook.Path & "\" & ThisWorkbook.Name, False
.Fields.Update
End With
End With
[/vba]
-
You only need the code I provided.
Didn't you notice a Range was specified ? A1:K10
Didn't you notice the double backslashes ?
Are you familiar with Thisworkbook.fullname ?
Last edited by snb; 03-05-2013 at 07:51 AM.
-
notice that but all the time I had "Error! Not a valid filename." maybe because I have (. - in excel name)
so this: ThisWorkbook.Path & "\" & ThisWorkbook.Name ..etc will not gone go?
-
or
[vba]
With ThisWorkbook.Worksheets(shName)
.Range(Cells(rand, 1).Address, Cells(l_row, coloana).Address).Columns.AutoFit
.Range(Cells(rand, 1).Address, Cells(l_row, coloana).Address).Copy
With wordDoc
.Fields.Add .Bookmarks("Tabel").Range, , "includetext" & ThisWorkbook.FullName & "A1:K10", False
.Fields.Update
End With
End With
[/vba]
but it is not working
-
Please do some closereading of my suggestions first.
-
but double backslashes ? can be "tricked" with:
ThisWorkbook.FullName
because I do not have any result:
[VBA]
With CreateObject("Word.Document")
.Fields.Add .Paragraphs(1).Range, , "includetext" & " " & ThisWorkbook.FullName & " " & "A1:K10", False
.Fields.Update
End With
[/VBA]
-
[vba]
Sub M_snb()
c01 = Replace(ThisWorkbook.FullName, ".xls", "_001.xls")
ThisWorkbook.SaveCopyAs c01
With CreateObject("Word.Document")
.Application.Visible = True
.Fields.Add .Paragraphs(1).Range, , "includetext " & c01 & " A1:K10", False
.Fields.Update
End With
End Sub
[/vba]
-
Good morning snb
Thank you for your solution.
but I will go via copy paste, because I have a "master sheet" that create the word document. and this master sheet is changing all the time.For revised document I will do: delete/keep existing table, insert new table.
to save a copy to "master sheet" is not an option.
mvg,
A.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules