PDA

View Full Version : extra space pops up when using macro



IkEcht
06-12-2007, 03:14 AM
Hi,

this is probably a simple question, but can't find the solution.

In my word document I paste loads of data from several excell worksheets, all with similar code like the one below:

Sub dir3g()
xl.Sheets("(deel)aspecttabellen").Select
xl.Range("b21").Select
xl.Selection.Copy
Selection.PasteSpecial DataType:=wdPasteText
End Sub

Now when I paste this, at most places in my document I get exactly what I want. But some places the field also gets replaced by a space and what I want to get from excell. This space is not in the excell sheet, nor in the sub, nor in the document, as far as I can see.

Anyone else who has this problem or anybody who can tell me where this stems from?

Thanks!

mdmackillop
06-12-2007, 05:41 AM
Try

Sub dir3g()
xl.Sheets("(deel)aspecttabellen").Select
With Range("b21")
.Value = Trim(.Value)
End With
End Sub

IkEcht
06-12-2007, 05:56 AM
Yeps that might solve the problem. Though in fact I haven't tried yet and know these problems to be persistent.

But a workaround doesn't solve my curiosity.. where do these spaces come from?

fumei
06-12-2007, 01:00 PM
It depends on what it is you are putting that data into. You don't say.

IkEcht
06-14-2007, 03:36 AM
There are several macro-fields within the document, all are just in the text (mostly pasting just one or two words or one number at a time).

So for instance:

"The score of <macrobutton:Place> on this test was <macrobutton:Score>, which is '<macrobutton:relativescore>' when compared to the scores of others."

Within the Excel sheet, the cell that contains Place would be a string, the cell that contains Score would be a number and the cell that contains relativescore would again be a string.
Then again they are all pasted as text. So doubt if that would make a difference, if it does, the problems seem to arise mostly with strings.