excel

How can I get a worksheet object from a specific workbook (not 'ThisWorkbook') using the worksheets CodeName?

六眼飞鱼酱① 提交于 2021-01-29 05:51:17
问题 I want to obtain a worksheet object from a specific workbook, like so: Set ws = Application.Workbooks("WorkBookName.xlsm").Worksheets("sheet1") However, I want to use the CodeName of the worksheet since the sheet's name can be changed. For example: Set ws = Application.Workbooks("WorkBookName.xlsm").Sheet1 Now, I know this doesn't work since Sheet1 is a global variable create by the VBA editor for convenience. I also know I could use the index (i.e. Worksheets(1)) to obtain the worksheet

How to jump to a specific cell based on the list selection

与世无争的帅哥 提交于 2021-01-29 05:47:52
问题 I have created a drop-down list in cell R5 containing names, lets call them Name1 Name2 Name3. I'd like when the user selects a certain name the sheet will scroll down to a specific row. For instance, if Name 1 is selected I'd like it to go to row 2, if Name2 is selected row 10, and Name3 row 18. The list is on the same worksheet as the data I'm wanting to scroll to. Is there some code I can use to do this? 回答1: You would need to use Sheet Events to handle this. Something like this: In your

keep Shell / cmd open when launching R script from VBA

回眸只為那壹抹淺笑 提交于 2021-01-29 05:46:40
问题 I have an R script that is being run from an Excel workbook via a button that is linked to a VBA script. The problem is every time the R script encounters an error - say it does not find one of the files it was supposed to read - the Shell / cmd window the R script is running in closes down instantly. The problem with that is you cannot see any clues as to why it failed. I then have to debug it manually by modifying the code and running in RStudio to find the errors - usually I have to do

Adding code for extracting Headings from Word Comments into Excel

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 05:42:33
问题 I have some code for extracting Comments from Word into Excel. However, it only extracts one level of Heading (the direct heading). What code can I add to extract different Heading levels in separate columns in Excel? And can I select these different heading level by Style e.g. if I use style MyOwnHeading, the code would pick that up as the Heading. Sub ExportWordComments() ' Purpose: Search for comments in any text that's been pasted into ' this document, then export them into a new Excel

Export Datagridview To XML File C#

送分小仙女□ 提交于 2021-01-29 05:41:48
问题 I have a requirement where I need to export data from excel file that import to a 'datagridview' to a specified format 'xml' firstly I fill to datagrid from excel and save as Xml ,folowing this code namespace SAMPLE_ { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Here I am using Microsoft Office Interop Excel to import Excel file: private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Microsoft.Office.Interop.Excel.Application

How can I allow for the entering of multiple lines of input into a VBA InputBox?

天大地大妈咪最大 提交于 2021-01-29 05:32:32
问题 I'm working on a macro that would allow me to type (or more likely, to paste) a SQL query into an InputBox and upon clicking "OK", it returns the results of the query against the database. The problem is, by default VBA only accepts one line of text and SQL code is written in a more structured, multi-line format for readability. When I try to paste SQL code into the InputBox , all but the first line of text are truncated. My next idea is to read the contents of the clipboard and replace any

Running VBA script with multiple URL's in one go

浪尽此生 提交于 2021-01-29 05:30:27
问题 I've managed to build a vba script that gets data form a website table. Everything works just the way I want it to work. But I need multiple tables and each time the website or table name needs to be different. As you can see below in the script I first get table 10 from the website, put it in Cell B2 and call it LT BE1 Home In the second sub I'm calling table 11 from the website, put it in Cell B22 (This is one cell below the previous table) and call it LT BE1 Away. In both cases the URL

VBA for removing duplicates in a specific column in another tab

半世苍凉 提交于 2021-01-29 05:30:26
问题 this is a simple issue with simple VBA but I have not been able to find the answer through multiple searches. I want to be able to remove duplicates in a column A in Sheet 2 of my workbook by pressing a button assigned to the macro in Sheet 1. This is the code I have assigned to the button in Sheet 1: Sub RemoveDupes() Sheets("Sheet2").Range("A1:A10350").RemoveDuplicates End Sub This code seems to just try to remove duplicates in the column in which the button exists or whatever column in

Masking Password in VBA Excel Input Box

冷暖自知 提交于 2021-01-29 05:20:24
问题 Could someone please help me to mask the password entered to the input box generated using the below code. I will be using Office 365 ProPlus. Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim sPassCheck As String Dim rng As Range Dim sTemp As String Dim sPassword As String sPassword = "12345" sTemp = "You must enter the password to delete data" ' Check if target is within Range N6:N100000 If Intersect(Target, Range("N6:N100000")) Is Nothing Then If Target.Count > 1 Then

VBA excel multiline string search

混江龙づ霸主 提交于 2021-01-29 05:10:38
问题 I want to search a multi line string in a text file using VBA excel macro. I tried using InStr function.But its not working as I expected. My exact aim is to read a multi line string stored in a cell and check whether it is available in a text file. For that what i did is read the text file in to a variable, reading the string saved in the cell to another variable and comparing using Instr using binary comparison. Will InStr work for multi line string? If not any any other way to compare it?