|
▼よろずや さん
またお時間空いてしまって申し訳ありません。
>提示したページはオートメーションのほんの一例です。
>オートメーションを使うとエクセルのすべての機能を使用できます。
>
>(1)新しいブックを作る。
>(2)テーブルデータをシートに貼り付ける。
>(3)罫線等を付ける。
>(4)新しいシートを追加する。
>(5)テーブルデータをシートに貼り付ける。
>(6)罫線等を付ける。
>(7)新しいシートを追加する。
>(8)テーブルデータをシートに貼り付ける。
>(9)罫線等を付ける。
>(10)ブックを保存する。
>すべてできます。
>
>createobject excel.application
>で検索してみてください。
教えていただいたページを参考に少しがんばってみました。
Attribute VB_Name = "Module1"
Option Compare Database
Sub 出力編集()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim strFilename As String
Dim strSheetName As String
strFilename = "C:\ファイル.xls"
strSheetName = "シート1"
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open Filename:=strFilename, UpdateLinks:=0
xlApp.Visible = True
Set xlBook = xlApp.Workbooks(Dir(strFilename))
Set xlSheet = xlBook.Worksheets(strSheetName)
’xlSheet.Cells(1, 1).Value = "HELLO"
xlSheets("strSheetName").Select
Range("A1:K41").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Range("A1:K1").Select
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
strSheetName = "シート2"
xlSheets("strSheetName").Select
Range("A1:AG71").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
strSheetName = "シート3"
xlSheets("strSheetName").Select
Range("A1:AG14").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
' xlApp.Run ("Macro4")
xlBook.Close saveChanges:=True
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
このようなカンジにつくってみたのですが、「SubまたはFunctionがありません」というエラーがでてしまいます。
1番上のこの行でした
xlSheets("strSheetName").Select
1度EXCELにマクロを作って、そちらを起動させようかとも考えたのですが・・・
できればACCESS内で完結させたいのでアドバイスいただけるとありがたいです。
よろしくお願いいたします。
|
|