Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

Moving Notes field from Project to Excel - Vba question - carriage returns

$
0
0

Hi all,

I am using some code I found on the internet to move my task data from project to excel. I have given the code below. My issue is that in the notes field the newline isnt preserved. I am looking for a line or two of code that will help preserve the carriage returns. I have given an example below. Any help would be much appreciated.

Example:

In project if I enter the following note:

This

is

a

world

Then the text gets printed to excel as: This is a world

Code:

Dim xlApp As Excel.Application

Dim xlRange As Excel.Range

Dim mtTask As Task

Dim Check As String

Sub ExportMasterData()

'Start Excel and create a new workbook

'Create column titles

'Export data and the project title

'Tidy up

'Start Excel and create a new workbook

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True

xlApp.Workbooks.Add

'Create column titles

Set xlRange = xlApp.Range("A1")

With xlRange

.Formula = "Master Task Report"

.Font.Bold = True

.Font.Size = 12

.Select

End With

xlRange.Range("A2") = "Task ID"

xlRange.Range("B2") = "Name"

xlRange.Range("C2") = "Start"

xlRange.Range("D2") = "Finish"

xlRange.Range("E2") = "Notes"

With xlRange.Range("A2:N2")

.Font.Bold = True

.HorizontalAlignment = xlHAlignCenter

.VerticalAlignment = xlVAlignCenter

.EntireColumn.AutoFit

.Select

End With

'Export data and the project title

Set xlRange = xlRange.Range("A3") 'Set cursor to the right spot in the worksheet

ViewApply Name:="Gantt Chart" 'Get the view that has the Text11 column to filter on

OutlineShowAllTasks 'Any hidden tasks won't be selected, so be sure all tasks are showing

SelectAll

For Each mtTask In ActiveSelection.Tasks 'Pulls data for each task into spreadsheet

With xlRange

.Range("A3") = mtTask.Text1

.Range("B3") = mtTask.Name

.Range("C3") = mtTask.Start

.Range("D3") = mtTask.Finish

.Range("E3") = mtTask.Notes

End With

Set xlRange = xlRange.Offset(1, 0) 'Point to next row

Next mtTask

'Tidy up

ViewApply Name:="Gantt Chart"

With xlRange

.Range("A3").ColumnWidth = 30

.Range("B3").ColumnWidth = 50

.Range("B3").EntireColumn.WrapText = True

.Range("C3").ColumnWidth = 30

.Range("D3").ColumnWidth = 30

.Range("E3").ColumnWidth = 50

.Range("E3").EntireColumn.WrapText = True

End With

Set xlApp = Nothing

End Sub

 


Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>