VBA Learning Notes (11)-Classic code (upgrade code in Visio)

Source: Internet
Author: User
Tags goto

Option ExplicitPrivate FunctionAdd () on Error GoToErrHandlerDimFilePath as String, FileName as StringFilePath=Application.ActiveDocument.Path FileName= FilePath +"Hello.bas"Visio.Application.Vbe.ActiveVBproject.VBComponents.Import (fileName)'Shell "cmd/c del" & FileName, Vbhide  Exit FunctionErrHandler:MsgBoxErr.DescriptionEnd FunctionPrivate Functiondel () on Error GoToErrHandlerDimModName as StringModName="Hello"  If(check (ModName) =1) ThenVisio.Application.Vbe.ActiveVBproject.VBComponents.Remove Visio.Application.Vbe.ActiveVBproject.VBComponents (ModName)End If  Exit FunctionErrHandler:MsgBoxErr.DescriptionEnd Function Public FunctionCall_ext ()PagerHello.helloEnd FunctionFunctionCheckByValModName as String) as Long   on Error GoToErrHandlerDimI check=0  'MsgBox Visio.Application.Vbe.ActiveVBproject.VBComponents.Count   fori =1  toVisio.Application.Vbe.ActiveVBproject.VBComponents.Count'MsgBox Visio.Application.Vbe.ActiveVBproject.VBComponents (i). Name     If(Visio.Application.Vbe.ActiveVBproject.VBComponents (i). Name = modname) ThenCheck=1     End If  NextIExit FunctionErrHandler:MsgBoxErr.DescriptionEnd FunctionFunctionAddcode (ByValBlockname as String,ByValCodeLine as Integer,ByValCodestring as String)   on Error GoToErrHandler'Insert  'With Visio.Application.Vbe.ActiveVBproject.VBComponents ("Update"). CodeModule  '  . InsertLines CodeLine, codestring  'End with    'ReplaceVisio.Application.Vbe.ActiveVBproject.VBComponents (blockname). Codemodule.replaceline CodeLine, codestringExit FunctionErrHandler:MsgBoxErr.DescriptionEnd Function'Sub Test ()'Call addcode ("Update", 2, "modname =" "Hello" "")'End Sub Public SubUpdate ()PagerdelPagerAdd'Call Call_ext    MsgBox "Update Done"End Sub

Includes deleting and adding modules;

Of course, you can also back up:

Option Explicit Public SubBackup () on Error GoToErrHandlerDimFilePath as String, FileName as StringFilePath=Application.ActiveDocument.PathfileName= FilePath +"Hello.bas"Visio.Application.Vbe.ActiveVBproject.VBComponents ("Hello"). Export (FileName)MsgBox "Backup Done"Exit SubErrHandler:MsgBoxErr.DescriptionEnd Sub

VBA Learning Notes (11)-Classic code (upgrade code in Visio)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.