首页 \ 问答 \ 在Outlook中定义Excel变量(Define Excel variable in Outlook)

在Outlook中定义Excel变量(Define Excel variable in Outlook)

我想从第3行开始遍历A列,并调试所有已填充的单元格的值。

我无法将变量定义为范围。 我认为问题在于我在Outlook VBA IDE中使用Excel VBA。

Sub Test2()

    Dim xlApp As Object
    Dim xlWB As Object
    Dim xlSheet As Object
    Dim enviro As String
    Dim strPath As String

    enviro = CStr(Environ("USERPROFILE"))

    'the path of the workbook
    strPath = enviro & "\Documents\test1.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
    Dim rw As Range
    Dim RowCount As Integer

    RowCount = 3

    For Each rw In xlSheet.Rows
        Debug.Print xlSheet.Cells(rw.Row, 1).Value
    Exit For

    RowCount = RowCount + 1

Next rw

xlWB.Close 1
If bXStarted Then
    xlApp.Quit
End If
End Sub

I want to iterate through column A, starting from row 3, and debug.print the values of all the populated cells.

I can't define a variable as range. I think the problem is that I'm using Excel VBA in an Outlook VBA IDE.

Sub Test2()

    Dim xlApp As Object
    Dim xlWB As Object
    Dim xlSheet As Object
    Dim enviro As String
    Dim strPath As String

    enviro = CStr(Environ("USERPROFILE"))

    'the path of the workbook
    strPath = enviro & "\Documents\test1.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
    Dim rw As Range
    Dim RowCount As Integer

    RowCount = 3

    For Each rw In xlSheet.Rows
        Debug.Print xlSheet.Cells(rw.Row, 1).Value
    Exit For

    RowCount = RowCount + 1

Next rw

xlWB.Close 1
If bXStarted Then
    xlApp.Quit
End If
End Sub

原文:https://stackoverflow.com/questions/45561898
更新时间:2023-07-26 22:07

最满意答案

您必须首先将值解包到其自己的(非可选)变量中。

let event = Event() ;
let pathArray = path.characters.split {$0 == "/"}.map { String($0) } ;
event.location = pathArray[2];

if let location = event.location { 
    print(location);
}

或者你可以放一个! 在event.location之后如果你想要的话。

let event = Event() ;
let pathArray = path.characters.split {$0 == "/"}.map { String($0) } ;
event.location = pathArray[2] ; 
print(event.location!) ;

you must unwrap the value first into its own (non optional) variable.

let event = Event() ;
let pathArray = path.characters.split {$0 == "/"}.map { String($0) } ;
event.location = pathArray[2];

if let location = event.location { 
    print(location);
}

or you could put an ! after event.location if you wanted.

let event = Event() ;
let pathArray = path.characters.split {$0 == "/"}.map { String($0) } ;
event.location = pathArray[2] ; 
print(event.location!) ;

相关问答

更多
  • if let表达式,则列出所有可能的字段,仅当所有字段not nil时才为真。 在你的情况下“let Question = jsonElement [”Question“]!as?String”将因“Category = 2”而失败。 所以if let块不会被执行。 You are listing all the possible fields in one if let expression, it is true only when all of them are not nil. In your ca ...
  • 您必须首先将值解包到其自己的(非可选)变量中。 let event = Event() ; let pathArray = path.characters.split {$0 == "/"}.map { String($0) } ; event.location = pathArray[2]; if let location = event.location { print(location); } 或者你可以放一个! 在event.location之后如果你想要的话。 let event = ...
  • UIApplicationDelegate协议的属性window是这样声明的: optional var window: UIWindow? { get set } 这意味着它是一个可选属性 (就像在Objective-C中有@optional时,“实现UIApplicationDelegate协议的类不需要实现/具有此属性 ”),并且该属性是可选类型 Optional (或UIWindow? )。 这就是为什么最后你有双重可选类型的原因,因为window属性可能会或可能不会在real ...
  • @MartinR在评论中提出了一个很好的观点: “为什么merge()接受inout参数?参数不会被修改,所以这似乎是一种不必要的复杂化。” 出错的原因是你在使用inout , DNode和DNode?时必须传递确切的类型DNode? 是两种不同的类型。 newNode需要声明为可选,因为这是合并期望的: func start(inout newNode: DNode?) { self.minDNode = merge(&self.minDNode, And: &newNode) // this c ...
  • 我认为你的意思是你想在单个逻辑表达式(而不是两个in和)中测试someString != nil 和 someString != "a" 。 不,我不认为使用内置运算符是可能的,但可以像这样实现字符串扩展: extension String { func isDifferentThan(value: String?) -> Bool { return value != nil && self != value? } } 你可以使用如下: someString = nil " ...
  • 如果您不想支持NSCoding,可以执行此操作: required init(coder: NSCoder) { fatalError("NSCoding not supported") } 如下所述: https : //stackoverflow.com/a/25128815/2611971 You can do this if you don't want to support NSCoding: required init(coder: NSCoder) { fatalError("NSC ...
  • cell.delegate? = self cell.delegate? = self应该是cell.delegate = self cell.delegate? = self should be cell.delegate = self
  • 为了知道为什么/如何工作你必须知道UIApplication如何在内部工作,所以任何想法为什么或为什么不是它是可选的纯粹是猜想。 如果委托是nil,应用程序退出或崩溃,或者只是允许初始化而不设置委托,并且他们选择不强制打开它以便它们可以处理错误情况。 In order to know why/how this works you would have to know how UIApplication works internally, so any idea as to why or why not it ...
  • 问题是let是不可变的。 一旦使用let关键字定义了一个变量或对象,就不能更改它,而在使用var您可以随时对它进行变异。 这就是原因,它说class has no initializers let someThing: Int? //Wrong let someThing: Int = 100 //Correct 供参考: swift中`let`和`var`有什么区别? 更新: 您可以在初始化程序中使用let关键字。 let name: String? init (name: String) { ...
  • 你只需要打开你收到的价值: - FIRDatabase.database().reference().child("Ring1Fighting").observe(.value) { (snap: FIRDataSnapshot) in print((snap.value as! String)) } You just need to unwrap the value that you recieve:- FIRDatabase.database().reference(). ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)