Consulting

Results 1 to 9 of 9

Thread: NUMBERS HELP

  1. #1
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    NUMBERS HELP

    Hi
    I have this code:
    [vba]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
    [/vba]
    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
    Last edited by Aussiebear; 02-10-2010 at 04:42 AM. Reason: Added VBA tags to code

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    Please go back to your post and wrap the code supplied with VBA tags
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    i do not understand what i need to do??

  4. #4
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    Hi
    I have this code:

    [VBA]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][/VBA]



    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
    Last edited by oleg_v; 02-01-2010 at 01:54 AM.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    Select your section of code and then click on the green vba button. This formats the code correctly and makes everything so much easier to read.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    is it right in mt previous post

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    No. Click on EDIT, then highlight your section of code then click on the green VBA button
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    I did what you asked.

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    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).Text)
    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •