perola.rike
Board Regular
- Joined
- Nov 10, 2011
- Messages
- 151
I have an Excel WB that export reports (text only) in a Word document. The code works perfectly, the text from the Word document are always further copied and pasted into the clinical journal system at hour hospital.
To save myself a few seconds more, I'd like to include some lines of code that
1) Copy the text in Word that includes not the whole document, but only copy the visible text (the word document alwas have many lines of empty space after the last sentence...)
2) If possible, a code that "removes spaces after paragraphs" in the word document.
I previosuly spent hours to figure out 2) before, no luck
Here is the code:
To save myself a few seconds more, I'd like to include some lines of code that
1) Copy the text in Word that includes not the whole document, but only copy the visible text (the word document alwas have many lines of empty space after the last sentence...)
2) If possible, a code that "removes spaces after paragraphs" in the word document.
I previosuly spent hours to figure out 2) before, no luck
Here is the code:
Code:
Sub wordexporte(ByRef wd As Object)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Sheets("export").Range("A1:A500").ClearContents
Sheets("jn").Range("A:D").EntireColumn.Hidden = False
Sheets("jn").Columns("I:I").Copy
Sheets("jn").Range("A:D").EntireColumn.Hidden = True
Set wsd = Sheets("export")
With wsd
.Range("A1:A200").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False
End With
ClearCell
Worksheets("export").Range("A1:A2000").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
Dim wdApp As Object, wdDoc As Object, wdRng As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Add
Sheets("export").Range("A1:A80").Copy
Set wdRng = wdDoc.Range
With wdRng
.Collapse Direction:=0
.Paste
.End = .Tables(1).Range.End + 1
.Tables(1).ConvertToText 0
.Font.Size = 12
.Copy
While .Paragraphs.Count > 1
.Paragraphs(1).Range.Characters.Last = Chr(11)
Wend
End With
wdApp.Visible = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Application.StatusBar = False
End Sub
Last edited by a moderator: