excel-vba

Excel date changed (month and day swapped) after reading and writing with VBA

走远了吗. 提交于 2020-01-30 05:41:05
问题 I wrote two lines of simple VBA codes to read from and write a date to a cell, but unexpectedly the month and day swapped after the run. The steps are: Enter a date "1/11/2017" in the cell A1. The date is now displayed as "01/11/2017". Run the following lines of code: Dim s As String s = Cells(1, 1).value Cells(2, 1).value = s The cell B1 now displays "11/01/2017" with the month and day swapped. My short date format setting in Region in Windows is "dd/MM/yyyy" so the string s stores the value

Optional ranges in vba function

隐身守侯 提交于 2020-01-30 04:55:14
问题 I am trying to return the columns count on a range, sometimes I need one range, but, sometimes I need more than one range. I have put in optional ranges so I can choose multiple ranges. If I reference a range in the function prototype that I have not supplied in the spreadsheet I get the #Value! error. I need a way to check if the optional ranges are null, void empty etc. so I don't have to reference the range. This is the VBA Function Prototype:- Function GetColoumnCount(ARange1 As Range,

web login using VBA

帅比萌擦擦* 提交于 2020-01-30 00:25:17
问题 I'm trying to access my webtext a/c using VBA. The first step is trying to get the tag for the username and password input boxes. I've used inspect elements to determine the tags and I think they are "username" and "password". However, this does not work. Unfortunately, I've no experience of CSS. Here is my code. Sub MyLogin() Set ie = CreateObject("InternetExplorer.Application") With ie .Visible = True .Navigate "http://www.o2online.ie/o2/login/" Do Until .ReadyState = 4 DoEvents Loop

web login using VBA

余生颓废 提交于 2020-01-30 00:24:10
问题 I'm trying to access my webtext a/c using VBA. The first step is trying to get the tag for the username and password input boxes. I've used inspect elements to determine the tags and I think they are "username" and "password". However, this does not work. Unfortunately, I've no experience of CSS. Here is my code. Sub MyLogin() Set ie = CreateObject("InternetExplorer.Application") With ie .Visible = True .Navigate "http://www.o2online.ie/o2/login/" Do Until .ReadyState = 4 DoEvents Loop

Listen to Windows messages in control, created with WinAPI, in VBA

佐手、 提交于 2020-01-29 19:42:24
问题 I had a great help with understanding how to correctly create controls (particularly, ListBox) in VBA with WinAPI. So, according to the structure, how VBA handles windows, we have three handles: hWin - UserForm's handle hClient - UserForm child's handle ( Server ) hList - ListBox's handle The question is - how to listen to Windows messages, incoming from Windows and generated by ListBox? 回答1: To listen to the messages, override the function that processes messages sent to a window, which is

Listen to Windows messages in control, created with WinAPI, in VBA

烂漫一生 提交于 2020-01-29 19:40:35
问题 I had a great help with understanding how to correctly create controls (particularly, ListBox) in VBA with WinAPI. So, according to the structure, how VBA handles windows, we have three handles: hWin - UserForm's handle hClient - UserForm child's handle ( Server ) hList - ListBox's handle The question is - how to listen to Windows messages, incoming from Windows and generated by ListBox? 回答1: To listen to the messages, override the function that processes messages sent to a window, which is

Listen to Windows messages in control, created with WinAPI, in VBA

99封情书 提交于 2020-01-29 19:39:54
问题 I had a great help with understanding how to correctly create controls (particularly, ListBox) in VBA with WinAPI. So, according to the structure, how VBA handles windows, we have three handles: hWin - UserForm's handle hClient - UserForm child's handle ( Server ) hList - ListBox's handle The question is - how to listen to Windows messages, incoming from Windows and generated by ListBox? 回答1: To listen to the messages, override the function that processes messages sent to a window, which is

Listen to Windows messages in control, created with WinAPI, in VBA

怎甘沉沦 提交于 2020-01-29 19:39:14
问题 I had a great help with understanding how to correctly create controls (particularly, ListBox) in VBA with WinAPI. So, according to the structure, how VBA handles windows, we have three handles: hWin - UserForm's handle hClient - UserForm child's handle ( Server ) hList - ListBox's handle The question is - how to listen to Windows messages, incoming from Windows and generated by ListBox? 回答1: To listen to the messages, override the function that processes messages sent to a window, which is

VBA: Copy cells, paste as a picture, then save as a picture?

旧城冷巷雨未停 提交于 2020-01-29 19:10:27
问题 I have the following code: Range("A1:M28").CopyPicture Appearance:=xlScreen, Format:=xlPicture Sheets.Add.Name = "Without Formatting" Worksheets("Without Formatting").Paste _ Destination:=Worksheets("Without Formatting").Range("A1:M28") That copies some cells then pastes them as a picture in another worksheet, is there a way of saving the picture (preferably as a jpeg) into a specific location so that I can then use the picture in an email? 回答1: I have used the following in the past. It

How to add a command button in VBA?

爷,独闯天下 提交于 2020-01-29 13:23:09
问题 I am trying to add a button to an Excel workbook so that it shows up in every sheet. A great answer to my original question gave me a macro to create the buttons on each sheet: Sub AddButtons() Dim ws As Excel.Worksheet Dim btn As Button For Each ws In ThisWorkbook.Worksheets Set btn = ws.Buttons.Add(X, Y, W, H) [set btn properties] Next ws End Sub I am now having trouble with setting the button properties so that the button prints the sheet when pressed. Again here is my print macro: Dim WS