oleg_v
01-31-2010, 11:37 PM
Hi
I have this code:
Sub XLToWordTable_3()
Dim ObjWord As Object
Dim wrdDoc As Object
Dim k As Integer
'Set the Word Object
Set ObjWord = CreateObject("Word.Application")
'Create a Document based on the template TableTest.dot
'You'll need to create the template ahead of time.
Set wrdDoc = ObjWord.Documents.Open(Filename:="C:\Documents and Settings\ovolfson\Desktop\function\KKK.doc")
'If there is more than one
'table, but sure to change it here.
With wrdDoc.Tables(18)
.Cell(4, 7) = CStr(Sheets("Sheet2").Range("B" & 3).Value)
End With
MyMonth = Left(MonthName(Month(Date)), 3)
MyDay = Day(Date)
Dim retv, d
d = Now
retv = Right("00" & Hour(d), 2) & Right("00" & Minute(d), 2)
MyFileName = MyMonth & "_" & MyDay & "_" & retv
'close and save .doc
myvar = Worksheets("Sheet1").Range("d1").Value
wrdDoc.SaveAs "C:\Documents and Settings\ovolfson\Desktop\function\" & myvar & "_" & MyFileName & ".doc" 'change file name to suit
wrdDoc.Close SaveChanges:=False
Set wrdDoc = Nothing
ObjWord.Quit
Set ObjWord = Nothing
Exit Sub
ErFix1:
On Error GoTo 0
MsgBox "error"
Set wrdDoc = Nothing
ObjWord.Quit
Set ObjWord = Nothing
End Sub
i have 1 problem when i transfer the numbers from excel to word:
when i have in excel cell the number looking like "0.05" or "0.5" when it transfers to word it looks like "05." or "5."
what can i do to make the numbers stay in their original form
Thanks
Oleg
I have this code:
Sub XLToWordTable_3()
Dim ObjWord As Object
Dim wrdDoc As Object
Dim k As Integer
'Set the Word Object
Set ObjWord = CreateObject("Word.Application")
'Create a Document based on the template TableTest.dot
'You'll need to create the template ahead of time.
Set wrdDoc = ObjWord.Documents.Open(Filename:="C:\Documents and Settings\ovolfson\Desktop\function\KKK.doc")
'If there is more than one
'table, but sure to change it here.
With wrdDoc.Tables(18)
.Cell(4, 7) = CStr(Sheets("Sheet2").Range("B" & 3).Value)
End With
MyMonth = Left(MonthName(Month(Date)), 3)
MyDay = Day(Date)
Dim retv, d
d = Now
retv = Right("00" & Hour(d), 2) & Right("00" & Minute(d), 2)
MyFileName = MyMonth & "_" & MyDay & "_" & retv
'close and save .doc
myvar = Worksheets("Sheet1").Range("d1").Value
wrdDoc.SaveAs "C:\Documents and Settings\ovolfson\Desktop\function\" & myvar & "_" & MyFileName & ".doc" 'change file name to suit
wrdDoc.Close SaveChanges:=False
Set wrdDoc = Nothing
ObjWord.Quit
Set ObjWord = Nothing
Exit Sub
ErFix1:
On Error GoTo 0
MsgBox "error"
Set wrdDoc = Nothing
ObjWord.Quit
Set ObjWord = Nothing
End Sub
i have 1 problem when i transfer the numbers from excel to word:
when i have in excel cell the number looking like "0.05" or "0.5" when it transfers to word it looks like "05." or "5."
what can i do to make the numbers stay in their original form
Thanks
Oleg