2017-11-08 1 views
0

こんにちは私はVBAをVBscriptに変換しようとしていますが、どこから起動するのか分からないので問題があります。どんな助けもありがとうございます。VBA unmergeとfilをVBscriptに変換してマージします

VBA:セルをアンマージし、元のマージされたデータセルからそれらのセルにデータを埋め込みます。

Sub UnMergeFill() 

Dim cell As Range, joinedCells As Range 

For Each cell In ThisWorkbook.ActiveSheet.UsedRange 
    If cell.MergeCells Then 
     Set joinedCells = cell.MergeArea 
     cell.MergeCells = False 
     joinedCells.Value = cell.Value 
    End If 
Next 

End Sub 

のVBScript:私は正しいExcelファイルを開いたり保存するためのコードの開始と終了ではなく、VBAスクリプトが実行される修飾を有します。

'create the excel object 
    Set objExcel = CreateObject("Excel.Application") 

'view the excel program and file, set to false to hide the whole process 
    objExcel.Visible = True 

'open an excel file (make sure to change the location) .xls for 2003 or earlier 
    Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Desktop\vbsTest.xlsx") 

'save the existing excel file 
    objWorkbook.Save 

'close the workbook 
    objWorkbook.Close 

'exit the excel program 
    objExcel.Quit 

'release objects 
    Set objExcel = Nothing 
    Set objWorkbook = Nothing 
+1

あなただけobjWorkbookではThisWorkbookを交換する必要があります。 – z32a7ul

答えて

0

のVBScriptコード:

'Microsoft Excel Automation 
':: Open, unmerge cells and fill then save 
'--------------------------------- 
'create the excel object 
    Set objExcel = CreateObject("Excel.Application") 

'view the excel program and file, set to false to hide the whole process 
    objExcel.Visible = True 

'open an excel file (make sure to change the location) .xls for 2003 or earlier 
    Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Desktop\Book3.xlsx") 

Dim cell 
Dim joinedCells 

For Each cell In objWorkbook.ActiveSheet.UsedRange 
    If cell.MergeCells Then 
     Set joinedCells = cell.MergeArea 
     cell.MergeCells = False 
     joinedCells.Value = cell.Value 
    End If 
Next 

'save the existing excel file 
    objWorkbook.Save 

'close the workbook 
    objWorkbook.Close 

'exit the excel program 
    objExcel.Quit 

'release objects 
    Set objExcel = Nothing 
    Set objWorkbook = Nothing 
関連する問題