Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
隐藏excel列不';不能在outlook vba中工作_Excel_Vba_Outlook - Fatal编程技术网

隐藏excel列不';不能在outlook vba中工作

隐藏excel列不';不能在outlook vba中工作,excel,vba,outlook,Excel,Vba,Outlook,我根本找不到在outlook vba中隐藏特定列的方法。我什么都试过了。我当前的代码如下: Sub ExportToExcel() Dim xlApp As Object Dim xlWB As Object Dim xlSheet As Object Dim enviro As String Dim strPath As String Dim ns As NameSpace Dim item As Object Dim inbox

我根本找不到在outlook vba中隐藏特定列的方法。我什么都试过了。我当前的代码如下:

Sub ExportToExcel()
    Dim xlApp As Object
    Dim xlWB As Object
    Dim xlSheet As Object
    Dim enviro As String
    Dim strPath As String
    Dim ns As NameSpace
    Dim item As Object
    Dim inbox As MAPIFolder
    Dim i As Long
    Dim j As Long

    ' Get Excel set up
enviro = CStr(Environ("USERPROFILE"))
'the path of the workbook
 strPath = enviro & "\Documents\test.xlsx"
     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(strPath)
     Set xlSheet = xlWB.Sheets("Sheet1")
    ' Process the message record
    `On Error Resume Next
    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
            For i = 2 To j - 1
                xlSheet.Columns(i).EntireColumn.Hidden = True
                Debug.Print xlSheet.cells(1, i).Value
            Next i
        Exit For
        End If
    Next j
     xlWB.Worksheets("Sheet1").Columns("A:NB").EntireColumn.AutoFit
     xlWB.Close 1
     If bXStarted Then
         xlApp.Quit
     End If
End Sub
子ExportToExcel()
将xlApp作为对象
作为对象的Dim xlWB
将图纸作为对象
Dim enviro As字符串
将strPath设置为字符串
Dim ns作为名称空间
将项目变暗为对象
将收件箱设置为MAPI文件夹
我想我会坚持多久
Dim j尽可能长
'设置Excel
enviro=CStr(环境(“用户档案”))
'工作簿的路径
strPath=enviro&“\Documents\test.xlsx”
出错时继续下一步
Set xlApp=GetObject(,“Excel.Application”)
如果错误为0,则
Application.StatusBar=“正在打开Excel源,请稍候…”
设置xlApp=CreateObject(“Excel.Application”)
bXStarted=True
如果结束
错误转到0
'打开工作簿以输入数据
设置xlWB=xlApp.Workbooks.Open(strPath)
设置xlSheet=xlWB.Sheets(“Sheet1”)
'处理消息记录
`出错时继续下一步
对于j=2至367
如果xlSheet.cells(1,j).Value日期和xlSheet.cells(1,j).Interior.ColorIndex=4,则
xlSheet.Columns(j).Interior.ColorIndex=0
如果结束
如果xlSheet.cells(1,j).Value=日期,则
xlSheet.Columns(j).Interior.ColorIndex=4
对于i=2到j-1
xlSheet.Columns(i).entireclumn.Hidden=True
Debug.Print xlSheet.cells(1,i).Value
接下来我
退出
如果结束
下一个j
xlWB.工作表(“表1”).列(“A:NB”).整个自动装配
xlWB.Close 1
如果BX启动,那么
xlApp.退出
如果结束
端接头
从“我的excel工作表”的第二列开始的第一行填充了从2017年1月1日到2017年12月31日的日期

我希望宏隐藏当前日期之前的所有日期。 如您所见,隐藏测试中的debug.print按预期工作,并打印从2017年1月1日到当前日期1的所有日期

作为旁注,xlSheet.Columns(i).Color=5287936也不起作用

通过将On Error Resume置于for in注释之前,我得到了一个“应用程序定义的或对象定义的错误”错误

如果删除所有错误测试,则会出现“ActiveX组件无法创建对象”错误


新发现,如果I
debug.print xlsheet.columns(I).hidden
我在即时窗口中得到一条“true”消息。显然,代码完全按照预期的方式执行,但它没有生效。

尝试手动自动调整。您应该会发现它取消隐藏隐藏列

移动Autofit,使其位于隐藏列之前,或者对要自动拟合的列进行更精确的调整

Set xlWB = xlApp.Workbooks.Open(strPath)
Set xlSheet = xlWB.Sheets("Sheet1")

xlWB.Worksheets("Sheet1").Columns("A:NB").EntireColumn.AutoFit

' Process the message record
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 And xlSheet.Cells(1, j).Interior.ColorIndex <> 0 Then
        xlSheet.Columns(j).Interior.ColorIndex = 4
    End If

    If xlSheet.Cells(1, j).Value = Date Then
        xlSheet.Columns(j).Interior.ColorIndex = 4
        For i = 2 To j - 1
            xlSheet.Columns(i).EntireColumn.Hidden = True
            Debug.Print xlSheet.Cells(1, i).Value
        Next i
        Exit For
    End If

Next j
Set xlWB=xlApp.Workbooks.Open(strPath)
设置xlSheet=xlWB.Sheets(“Sheet1”)
xlWB.工作表(“表1”).列(“A:NB”).整个自动装配
'处理消息记录
对于j=2至367
如果xlSheet.Cells(1,j).Value日期和xlSheet.Cells(1,j).Interior.ColorIndex=4,则
xlSheet.Columns(j).Interior.ColorIndex=0
如果结束
如果xlSheet.Cells(1,j).Value日期和xlSheet.Cells(1,j).Interior.ColorIndex为0,则
xlSheet.Columns(j).Interior.ColorIndex=4
如果结束
如果xlSheet.Cells(1,j).Value=日期,则
xlSheet.Columns(j).Interior.ColorIndex=4
对于i=2到j-1
xlSheet.Columns(i).entireclumn.Hidden=True
Debug.Print xlSheet.Cells(1,i).Value
接下来我
退出
如果结束
下一个j

尝试手动自动调整。您应该会发现它取消隐藏隐藏列

移动Autofit,使其位于隐藏列之前,或者对要自动拟合的列进行更精确的调整

Set xlWB = xlApp.Workbooks.Open(strPath)
Set xlSheet = xlWB.Sheets("Sheet1")

xlWB.Worksheets("Sheet1").Columns("A:NB").EntireColumn.AutoFit

' Process the message record
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 And xlSheet.Cells(1, j).Interior.ColorIndex <> 0 Then
        xlSheet.Columns(j).Interior.ColorIndex = 4
    End If

    If xlSheet.Cells(1, j).Value = Date Then
        xlSheet.Columns(j).Interior.ColorIndex = 4
        For i = 2 To j - 1
            xlSheet.Columns(i).EntireColumn.Hidden = True
            Debug.Print xlSheet.Cells(1, i).Value
        Next i
        Exit For
    End If

Next j
Set xlWB=xlApp.Workbooks.Open(strPath)
设置xlSheet=xlWB.Sheets(“Sheet1”)
xlWB.工作表(“表1”).列(“A:NB”).整个自动装配
'处理消息记录
对于j=2至367
如果xlSheet.Cells(1,j).Value日期和xlSheet.Cells(1,j).Interior.ColorIndex=4,则
xlSheet.Columns(j).Interior.ColorIndex=0
如果结束
如果xlSheet.Cells(1,j).Value日期和xlSheet.Cells(1,j).Interior.ColorIndex为0,则
xlSheet.Columns(j).Interior.ColorIndex=4
如果结束
如果xlSheet.Cells(1,j).Value=日期,则
xlSheet.Columns(j).Interior.ColorIndex=4
对于i=2到j-1
xlSheet.Columns(i).entireclumn.Hidden=True
Debug.Print xlSheet.Cells(1,i).Value
接下来我
退出
如果结束
下一个j

注释不适用于扩展讨论或调试会话。不要在注释中发布代码。当有人向你询问代码或说明时,你需要将其纳入你的问题中。上一次对话是。您正在运行哪个office?我使用office 2010。评论不用于扩展讨论或调试会话。不要在注释中发布代码。当有人向你询问代码或说明时,你需要将其纳入你的问题中。前面的对话是。你在经营哪个办公室?我用的是office 2010。