Pasting into Word

aworbey

New Member
Joined
Jun 3, 2008
Messages
12
I'm hoping someone can help me here. I'm running the following macro which outputs to a word document, however I am having problems when it comes to pasting dates as they seem to paste as hashes, instead of date into word. Everything else pastes fine but dates dont seem too. The folder path is set before this macro but didnt think that was needed as it's this bit it goes wrong at.

Code:
Private Sub cmdOpen_Click()
Dim OpenOrNot As Integer
 
If txtBrowse1 = "" Then
MsgBox "You need to choose a folder to save the document to first"
Exit Sub
Else
Dim fieldsfound As Integer
'   Creates document in word using Automation
    Dim WordApp As Object
'   Start Word and create an object
    Set WordApp = CreateObject("Word.Application")
 
'       Update status bar progress message
        Application.StatusBar = "Processing AB Record"
 
'       Determine the file name
        SaveAsName = Curfolder1 & "\" & "AB Survey details for " & Range("F2").Offset(ChosenRecord, 0).Value & " on " & Format(Range("F2").Offset(ChosenRecord, 1).Value, "dd-mm-yyyy") & ".doc"
'       Send commands to Word
        With WordApp
                .Documents.Add ("O:\Sections\AB.dot")
            With .Selection
                .Font.Size = 12
                .Font.Bold = True
                .Font.Name = "Arial"
                .Font.Underline = True
                .ParagraphFormat.Alignment = 1
                .TypeText Text:="ASB Survey"
                .Font.Size = 11
                .TypeParagraph
                .TypeParagraph
                .Font.Bold = False
                .Font.Name = "Arial"
                .Font.Underline = False
                .ParagraphFormat.Alignment = 0
                .TypeParagraph
 
                For fieldsfound = 1 To 70
                Range("E2").Offset(0, 0 + fieldsfound).Copy
                .PasteSpecial
                Range("E2").Offset(ChosenRecord, 0 + fieldsfound).Copy
                .PasteSpecial
                .TypeParagraph
                Next fieldsfound
            End With
                .ActiveDocument.SaveAs Filename:=SaveAsName
                .ActiveDocument.Close
                WordApp.Quit
                Set WordApp = Nothing
        End With
'   Reset status bar
    Application.StatusBar = "Word Output Complete :)"
    Application.StatusBar = ""
End If
Unload Me
OpenOrNot = MsgBox("The output process to Word is complete" & " documents have been created and saved in " & Curfolder1 & Chr(13) & "Would you like to open the Word output file now?", vbYesNo)
If OpenOrNot = vbYes Then
    Set WordApp = CreateObject("word.Application")
    WordApp.Documents.Open SaveAsName
    WordApp.Visible = True
 
End If
 
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,598
Messages
6,179,818
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top