Excel cell font and color transfer to Visio VBA

Started by Zodiac69, November 22, 2023, 06:47:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zodiac69

I read an excel spreadsheet, about 400 lines x 57 Columb's and generate a Visio page from a "Base" template for every line.
This is working well, but i would like to know how can i also read the font and color of the cell?
I want to make certain text RED, Italic and Bold in the Excel sheet and then transfer the text properties over when i create the Visio pages.



Surrogate

#1
You can iterate Excel's range with code like this
Sub nnn()
Dim R As Integer ' ROW INDEX
Dim exApp As Object ' EXCEL APP instance
Set exApp = GetObject(, "Excel.Application")
Dim exWB As Object ' Excel workbook
Set exWB = exApp.ActiveWorkbook
Dim exSHT As Object ' Excel's active sheet
Set exSHT = exWB.ActiveSHEET
Dim rng As Object ' Excel' cell
With exSHT
For R = 1 To 3 ' iterate cells
Set rng = .Cells(R, 1)
    Debug.Print rng.Font.Color ' 255 - red, 65280 - green, 16711680 - blue
    Debug.Print rng.Font.Name
    Debug.Print rng.Font.Bold ' boolean
    Debug.Print rng.Font.Italic ' boolean
Next
End With
End Sub

Excel's and Visio colors are different!


Nikolay

One approach to this is to use copy-paste.
When iterating over cells in Excel, use "copy" command and then use "paste" to paste the text into visio shape (it should copy-paste "rich text" by default, i.e. keeping text color and format)
You can try to do it manually first to see if the result is satisfactory.

Copying Excel fill style to Visio formatting may be complicated as hell.
Don't do it unless you really have to.