vba

Set Excel Range Formatting With Array

﹥>﹥吖頭↗ 提交于 2021-02-07 14:50:37
问题 I have, in the past, used a variant array to populate a range of multiple Excel cells. I'm wondering, is there a way to do the same thing with cell formatting? I'd rather not go cell by cell, and it'd be nice to minimize the number of calls to get an Excel range... 回答1: @ExcelHero has pointed out to me how to get this done, so here's how. If your range is horizontal, then just feed it an array built of Format strings: [a1:c1].NumberFormat = Array("hh:mm", "General", "$#,##0.00") If your range

Excel VBA: how to add data validation list which contain comma included value without using reference of Range

我的未来我决定 提交于 2021-02-07 14:16:49
问题 I need to add a data validation list to Cell whose few values contains comma. I have the same problem like this Data Validation to Include Comma Character But I can't reference a range, because I am creating a new workbook and feed its cell with the data validation list. So reference is not working for me and since some values contain comma so I can't set the Range into String and use that after Formula1 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1

Convert String to Excel Date and Time, with specific string format

不羁岁月 提交于 2021-02-07 14:15:13
问题 I've got an Excel/VBA macro which list files in a directory. Filenames are in format : yyyy-MM-dd@hh-mm-ss_[description].csv for instance : 2013-07-03@22-43-19_my-file.csv I then need to get the first part of the filename into an Excel Date object (including a Timestamp) I found the CDate() function, but it doesn't take any "format" parameter, and the Format() function works the wrong way, ie to convert a String to a Date. I'd like to get a function with takes a String and a format, and

Difference between VBA.CBlah and CBlah

℡╲_俬逩灬. 提交于 2021-02-07 14:13:58
问题 Weird observation: Normally when I want to save an address to a function in a variable, I do something like this: Function getAddress(ByVal func As LongPtr) As LongPtr getAddress = func End Function Sub printAddress() Dim functionPointer As LongPtr functionPointer = getAddress(AddressOf myFunc) Debug.Print functionPointer End Sub However I just discovered I can use a 1-liner functionPointer = VBA.CLngPtr(AddressOf myFunc) while functionPointer = CLngPtr(AddressOf myFunc) ... does not work and

Convert String to Excel Date and Time, with specific string format

时光毁灭记忆、已成空白 提交于 2021-02-07 14:13:16
问题 I've got an Excel/VBA macro which list files in a directory. Filenames are in format : yyyy-MM-dd@hh-mm-ss_[description].csv for instance : 2013-07-03@22-43-19_my-file.csv I then need to get the first part of the filename into an Excel Date object (including a Timestamp) I found the CDate() function, but it doesn't take any "format" parameter, and the Format() function works the wrong way, ie to convert a String to a Date. I'd like to get a function with takes a String and a format, and

Difference between VBA.CBlah and CBlah

别说谁变了你拦得住时间么 提交于 2021-02-07 14:11:18
问题 Weird observation: Normally when I want to save an address to a function in a variable, I do something like this: Function getAddress(ByVal func As LongPtr) As LongPtr getAddress = func End Function Sub printAddress() Dim functionPointer As LongPtr functionPointer = getAddress(AddressOf myFunc) Debug.Print functionPointer End Sub However I just discovered I can use a 1-liner functionPointer = VBA.CLngPtr(AddressOf myFunc) while functionPointer = CLngPtr(AddressOf myFunc) ... does not work and

Difference between VBA.CBlah and CBlah

僤鯓⒐⒋嵵緔 提交于 2021-02-07 14:11:07
问题 Weird observation: Normally when I want to save an address to a function in a variable, I do something like this: Function getAddress(ByVal func As LongPtr) As LongPtr getAddress = func End Function Sub printAddress() Dim functionPointer As LongPtr functionPointer = getAddress(AddressOf myFunc) Debug.Print functionPointer End Sub However I just discovered I can use a 1-liner functionPointer = VBA.CLngPtr(AddressOf myFunc) while functionPointer = CLngPtr(AddressOf myFunc) ... does not work and

Difference between VBA.CBlah and CBlah

怎甘沉沦 提交于 2021-02-07 14:09:47
问题 Weird observation: Normally when I want to save an address to a function in a variable, I do something like this: Function getAddress(ByVal func As LongPtr) As LongPtr getAddress = func End Function Sub printAddress() Dim functionPointer As LongPtr functionPointer = getAddress(AddressOf myFunc) Debug.Print functionPointer End Sub However I just discovered I can use a 1-liner functionPointer = VBA.CLngPtr(AddressOf myFunc) while functionPointer = CLngPtr(AddressOf myFunc) ... does not work and

Using ranges, how can I make a .COPY DESTINATION paste as VALUES

萝らか妹 提交于 2021-02-07 13:37:44
问题 I have the following code, which works just fine to copy the entire cells to their new destination. Dim ws As Worksheet, rng As Range Set ws = Sheets("Duplicates") Set rng = ws.Range("A2") rng.Copy Destination:=Range("A2:A" & Range("G" & Rows.Count).End(xlUp).Row) Is it possible to make that cope a paste special . Or do I need to split the copy/paste into two lines using a two range objects? EDIT: Right, we've concluded that you CANNOT have a paste special on the same line as a copy. What I

Call Powershell Script from VBA(with Parameter)

感情迁移 提交于 2021-02-07 13:25:44
问题 I want to call a Powershell-Script from Excel VBA and pass 1 Parameter. Without VBA the Script works perfectly and does what it supposed to do.. As soon as the Call works, i would like to add 1 parameter, but first the successfull call... But i cant manage to call it within Excel VBA. First ill show you my Powershell-Script: #param([string]$server) $server = "chvmes01" $BasicPath = Split-Path $script:MyInvocation.MyCommand.Path write-host $BasicPath Invoke-Command -FilePath $BasicPath