Rename visio

Rafaelete

New Member
Joined
Feb 2, 2022
Messages
14
Office Version
  1. 2007
Platform
  1. Windows
Hello,

I have been searching for a way to replace inside words inside a visio using the information within two columns in excel. The columns are in the excel that has the macro, Sheet name: "Intro", the columns are: Column B: Original words, Column C: Words to be replaced.
I have been able to do it, but the code runs to each sheet in visio, one by one. But I want it to do a replace all to run faster, I have seen that visio has an option to replace in all pages at once. Any ideas on how to do that will be greatly appreciated:

-Excel columns:

1648653693064.png

- Visio:
1648653808567.png
Is currently chainging the information in a bunch of visios that are inside subfolders. As you can see, in this examples, it has your sheets, is going through each, one by one. There is an option in visio to find, replace in all pages. I need to get it to work here as well because is taking a long time replacing each visio. Thanks a lot.

On Error GoTo CambiarTextoEnFicheroVisio_Error

Dim aVisio As Object ' Visio.Application
Dim aDocument As Object ' Visio.Document
Dim i As Integer
Dim iBegin As Integer
Dim iPage As Integer
Dim iTextosASustituir As Integer
Dim sFileNamePdf As String
Dim sAux As String


' Obtener documento
Set aVisio = CreateObject("Visio.Application")

' Set aDocument = aVisio.Documents.OpenEx("path used", Flags:=Visio.visOpenRW)
Set aDocument = aVisio.Documents.OpenEx("path used", Flags:=visOpenRW)


' Recorrerse todas las páginas
For iPage = 1 To aVisio.ActiveDocument.Pages.Count

aVisio.ActiveWindow.Page = aVisio.ActiveDocument.Pages(iPage)

' Recorrerse todas las formas
For i = 1 To aVisio.ActiveWindow.Page.Shapes.Count

' Modificar todos los textos
For iTextosASustituir = 1 To colTextosOriginales.Count
' Dim vsoCharacters As Visio.Characters
Dim vsoCharacters As Object

Set vsoCharacters = aVisio.ActiveWindow.Page.Shapes(i).Characters
iBegin = InStr(1, vsoCharacters.Text, colTextosOriginales.Item(iTextosASustituir))

If iBegin > 0 Then
iBegin = iBegin - 1 ' En visio para sustituir hay que situarse uno por detrás
vsoCharacters.Begin = iBegin
vsoCharacters.End = vsoCharacters.Begin + Len(colTextosOriginales.Item(iTextosASustituir))
vsoCharacters.Text = colTextosFinales.Item(iTextosASustituir)
End If
Next iTextosASustituir
Next i
Next iPage

aDocument.SaveAs CambiarNombreFichero("path used")

'Imprimir en Pdf
If bExportarPdF Then
sAux = CambiarNombreFichero("path used")
sFileNamePdf = CambiarNombreFicheroAPdF(sAux)

' aVisio.ActiveDocument.ExportAsFixedFormat Visio.visFixedFormatPDF, sFileNamePdf, Visio.visDocExIntentPrint, Visio.visPrintAll, 1, aVisio.ActiveDocument.Pages.Count, False, True, True, True, False
aVisio.ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, sFileNamePdf, visDocExIntentPrint, visPrintAll, 1, aVisio.ActiveDocument.Pages.Count, False, True, True, True, False
End If

aDocument.Close
aVisio.Quit
Set aVisio = Nothing
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,215,079
Messages
6,123,000
Members
449,092
Latest member
masterms

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