夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          '******************************************************************************
          '
          * File:     excel2pdm.txt
          '
          * Title:    pdm export to excel
          '
          * Purpose:  To export the tables and columns to Excel
          '
          * Model:    Physical Data Model
          '
          * Objects:  Table, Column, View
          '
          * Author:   ziyan
          '
          * Created:  2012-05-03
          '
          *Modifier:  Hui Wanpeng 2014/07/04
          '
          * Version:  1.0
          '
          ******************************************************************************
          Option Explicit

          Dim md1 'the current model
          Set md1=ActiveModel
          If(md1 Is NothingThen
            
          MsgBox "There is no Active Model"
          End If

          Dim HaveExcel
          Dim RQ
          RQ 
          = vbYes 'MsgBox("Is Excel Installed on your machine?",vbYesNo+vbInformation,"Confirmation")

          If RQ=vbYes Then
            HaveExcel
          =True
            
          'Open&Create Excel Document
            Dim x1
            
          set x1=CreateObject("Excel.Application")
            x1.Workbooks.Open 
          "E:/tmp/B超檢查表.xls"
            x1.Workbooks(
          1).Worksheets("Sheet1").Activate
          Else
            HaveExcel
          =False
          End If

          process x1, md1

          sub process(x1,md1)
              
          dim rwIndex
              
          dim tableName
              
          dim colname
              
          dim table
              
          dim col
              
          dim count
              
          dim dType
              
          dim nNull

              
          'on error Resume Next
              For rwIndex =1 To 500 step 1
                 
          With x1.Workbooks(1).Worksheets("Sheet1")
                    
          If .Cells(rwIndex,1).Value="" Then
                       
          Exit For
                    
          End If
                    
          If .Cells(rwIndex,3).Value="" Then
                        
          set table=md1.Tables.CreateNew
                        table.Name
          =.Cells(rwIndex,2).Value
                        table.Code
          =UCase(.Cells(rwIndex,1).Value)
                        table.Comment
          =.Cells(rwIndex,2).Value
                        count
          =count+1
                    
          Else
                        colName
          =.Cells(rwIndex,1).Value
                        
          set col=table.Columns.CreateNew
                        
                        
          'MsgBox.Cells(rwIndex,1).Value
                         'MsgBox colName,vbOK+vbInformation,"列"
                        col.Code=Trim(UCase(.Cells(rwIndex,1).Value))
                        col.Name
          =Trim(UCase( .Cells(rwIndex,1).Value))
                        col.Comment
          =Trim(.Cells(rwIndex,2).Value)
                     
                        dType
          =Trim(UCase(.Cells(rwIndex,3).Value))
                        
          'MsgBox Left(dType, 5)
                        If Left(dType, 5)="CHAR(" Then
                            dType
          =Replace(dType,"CHAR","VARCHAR2")
                        
          ElseIf Left(dType, 5)="CAHR(" Then 
                            dType
          =Replace(dType,"CAHR","VARCHAR2")
                        
          End If
                        col.DataType
          =dType
                     
                        nNull
          =Trim(UCase(.Cells(rwIndex,4).Value))
                        
          If nNull="NOT NULL" then
                          col.Mandatory
          ="true"
                        
          End If
                     
                   
          End If
                 
          End With
              
          Next

              
          MsgBox "生成數據表結構共計 " + CStr(count), vbOK+vbInformation, ""
              x1.Workbooks.Close
              
          Exit Sub

          End Sub


          posted on 2014-07-06 21:06 HUIKK 閱讀(393) 評論(0)  編輯  收藏 所屬分類: VB/VBA/VBS

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 宁海县| 高雄县| 吴堡县| 连城县| 宜兰市| 六盘水市| 普格县| 固阳县| 湖南省| 巧家县| 博爱县| 德令哈市| 铜陵市| 邵阳市| 三门县| 拜泉县| 通榆县| 深水埗区| 泽州县| 隆林| 静宁县| 黑水县| 莱西市| 修水县| 凤翔县| 石渠县| 任丘市| 河北省| 监利县| 邮箱| 桐柏县| 循化| 瑞安市| 文山县| 平遥县| 大余县| 桃江县| 洪江市| 苍溪县| 通江县| 陇南市|