在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 = ...
-
可选的Swift可选(Swift Optional of Optional)[2022-09-04]
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 ...
-
可选var未设置(optional var not getting set)[2023-11-12]
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(). ...