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