MXD の SDE データ ソースを再設定

Private Sub ReConnectToSDE()
    Dim pMapDocument As IMapDocument
    Set pMapDocument = New MapDocument
    pMapDocument.Open "D:\Workspace\Support\PathA.mxd"          '対象マップ ドキュメント
    
    Dim intMap As Integer
    
    For intMap = 0 To pMapDocument.MapCount - 1
       
        Dim pMap As IMap
        Set pMap = pMapDocument.Map(intMap)
                
        Dim pLayers As IEnumLayer
        Set pLayers = pMap.Layers
        
        Dim pLayer As ILayer
        Set pLayer = pLayers.Next
        
        Do Until pLayer Is Nothing
            
            Dim pPropertySet As IPropertySet
            Set pPropertySet = New PropertySet
            
            'ArcSDE接続情報
            With pPropertySet
                .SetProperty "Server", "ServerName"               'サーバ
                .SetProperty "Instance", "5151"                 'インスタンス
                .SetProperty "Database", ""                     'データベース
                .SetProperty "user", "UserName"                    'ユーザ名
                .SetProperty "password", "UserPass"              'パスワード
                .SetProperty "version", "SDE.DEFAULT"           'バージョン
            End With
            
            Dim pDataLayer As IDataLayer
            Set pDataLayer = pLayer
            
            Dim pDatasetName As IDatasetName
            Set pDatasetName = pDataLayer.DataSourceName
            
            Dim pWorkspaceName As IWorkspaceName
            Set pWorkspaceName = New WorkspaceName
            
            pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory"
            pWorkspaceName.ConnectionProperties = pPropertySet  'ArcSDE接続情報
            
            pDatasetName.Name = "aaa"                           'フィーチャクラス名
            
            Set pDatasetName.WorkspaceName = pWorkspaceName
            
            Set pLayer = pLayers.Next
            
        Loop
        
    Next intMap
    
    pMapDocument.Save True, False
    pMapDocument.Close
        
End Sub