Outlook VBAマクロを実行するとExcelプロセスが停止しません。私はそれがいくつかのExcelのオブジェクト関数によって引き起こされたと思われるが、私は本当にどちらがわからない。 問題は、Excelブックが置かれているフォルダに複数の.tmpファイルを作成することによっても現れます。(私は思いますか?) Excelを開いて閉じるためのコードとExcelを使用するすべてのメソッドを投稿しますオブジェクト。.Quitの後でもExcelプロセスがまだ実行中です
Option Explicit
Public xlApp As Object
Public xlWB As Object
Public xlSheet As Object
Sub LeaveRequests()
Dim enviro As String
Dim strPath As String
Dim filePath As String
Dim bXStarted As Boolean
Dim i As Long
Dim j As Long
'Get Excel set up
enviro = CStr(Environ("USERPROFILE"))
'the path of the workbook
filePath = enviro & "\AppData\Roaming\Microsoft\Outlook\path.txt"
Open filePath For Input As #1
Do Until EOF(1)
Line Input #1, strPath
Loop
Close #1
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Application.StatusBar = "Please wait while Excel source is opened ... "
Set xlApp = CreateObject("Excel.Application")
bXStarted = True
End If
On Error GoTo 0
'Open the workbook to input the data
Set xlWB = xlApp.Workbooks.Open(enviro & strPath)
Set xlSheet = xlWB.Sheets("Sheet1")
' Process the message record
On Error Resume Next
xlWB.Worksheets("Sheet1").Columns("A:NB").entirecolumn.AutoFit
For j = 2 To 367
If xlSheet.cells(1, j).Value <> Date And xlSheet.cells(1, j).Interior.ColorIndex = 4 Then
xlSheet.Columns(j).Interior.ColorIndex = 0
End If
If xlSheet.cells(1, j).Value = Date Then
xlSheet.Columns(j).Interior.ColorIndex = 4
xlSheet.Columns(j).Select
If xlSheet.cells(2, j).Value = "Monday" Then
For i = 2 To j - 1
xlSheet.Columns(i).Hidden = True
Next i
End If
xlWB.Close SaveChanges:=True
If bXStarted Then
xlApp.Quit
End If
End Sub
これはExcelの開閉です。 私はまた、leaverequestsサブのinbox反復中に呼ばれるサブを持っています。
Sub FillIn(ByVal x As String, ByVal y As Date, ByVal z As Date, ByVal id As String)
Dim currentRow As Long
Dim i As Long
Dim j As Long
Dim date1Pos As Integer
Dim date2Pos As Integer
Dim datePos As Integer
Dim lastRow As Integer
lastRow = xlSheet.Range("A" & xlSheet.Rows.Count).End(-4162).Row
date1Pos = 0
date2Pos = 0
For i = 3 To lastRow
If xlSheet.cells(i, 1).Value = id Then
currentRow = i
Exit For
End If
Next i
For j = 2 To 367
If xlSheet.cells(1, j).Value = y Then
date1Pos = j
End If
If xlSheet.cells(1, j).Value = z Then
date2Pos = j
Exit For
End If
Next j
If date1Pos <> 0 And date2Pos <> 0 Then
datePos = date1Pos
For j = 1 To date2Pos + 1 - date1Pos
xlSheet.cells(currentRow, datePos).Value = x
xlSheet.cells(currentRow, datePos).HorizontalAlignment = xlCenter
datePos = datePos + 1
Next j
End If
End Sub
'367'にJ = 2の場合はそれがないマッチング' Next' –
を持っていないようです、それは正しい 'もしdate1Pos <> 0とdate2Pos <> 0 Then'より上ですコードをインデントしてみます。 – NAlexP
申し訳ありませんLeaveRequestsの「次のJ」が表示されません –