excel-vba

excel vba to upload file to sharepoint

和自甴很熟 提交于 2020-01-23 12:03:20
问题 I am trying to upload a folder from my C drive to a SharePoint library site. I have used the below code, which works fine when the ToPath is not a SharePoint library site but another folder from my C drive. Where am I going wrong? Sub AddSharePointFiles() Dim FSO As Object Dim FromPath As String Dim ToPath As String ToPath = "https://share.name.com/site/folder/_layouts/15/start.aspx#/LibraryName/Forms/AllItems.aspx" FromPath = "C:\Users\Name\Documents\FolderName" Set FSO = CreateObject(

Add a macro to the right-button menu

最后都变了- 提交于 2020-01-23 11:31:56
问题 I would like to add a created macro to the right-button menu. Is it possible? Thanks a lot! 回答1: If you meant add a macro to the options when you right click you mouse then you could try this code CreateMacro which assigns Test_Macro to the right click menu with a caption YourCode . Run KillMacro to remove the menu item Const strMacro = "YourCode" Sub CreateMacro() Dim cBut Call KillMacro Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True) With cBut .Caption = strMacro

Looping Through EXCEL VBA Dictionary

若如初见. 提交于 2020-01-23 03:21:25
问题 I have a VBA Dictionary with the following data: ID NAME POSITION 5008004 John Doe 00120096 5008002 John Doe2 00117886 5010010 John Doe3 00117886 I have an Excel documented with the following cells: POSITION SUPERVISOR_NAME 00117886 John Doe 00117886 John Doe2 00117886 John Doe3 Current Excel VBA code loops through the dictionary in the following fashion: If SUPERVISOR_NAME <> "" Then For Each myKey In superDictionary.Keys If superDictionary(myKey) = SUPERVISOR_NAME Then SUPERVISOR_NAME =

Mac Excel generate UTF-8 using VBA

∥☆過路亽.° 提交于 2020-01-23 01:44:44
问题 Is it possible to generate a UTF-8 file using Visual Basic (VBA) in Excel 2016 for Mac? I need to generate an XML or TXT file that is encoded. Thanks 回答1: Not UTF-8, but UTF-16 is what VBA uses internally, so you can dump string data directly: Dim fnum As Integer fnum = FreeFile() Open "utf16.txt" For Binary Access Write As fnum 'write UTF-16 Byte Order Marker ' Put #fnum, 1, &HFE Put #fnum, 2, &HFF printLineUtf16 fnum, "Olá Mundo!" Close #fnum Function printLineUtf16(fnum As Integer, str As

Importing Delimited File to Excel with Macro (.CommandType = 0)

╄→尐↘猪︶ㄣ 提交于 2020-01-23 01:37:27
问题 Lots of similar questions going on but google and stack overflow are not touching the part I think I need. I am trying to import a pipe delimited text file with a macro. When I record macro, this is what I get: With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;C:\Users\johnsmith\Desktop\Macro Tinkering\ABC_Financials_ALL(Delimited).txt" _ , Destination:=Range("$A$1")) .CommandType = 0 .Name = "ABC_Financials_ALL(Delimited)_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas =

Random Number Generation to Memory from a Distribution using VBA

孤者浪人 提交于 2020-01-23 01:25:26
问题 I want to generate random numbers from a selected distribution in VBA (Excel 2007). I'm currently using the Analysis Toolpak with the following code: Application.Run "ATPVBAEN.XLAM!Random", "", A, B, C, D, E, F Where A = how many variables that are to be randomly generated B = number of random numbers generated per variable C = number corresponding to a distribution 1= Uniform 2= Normal 3= Bernoulli 4= Binomial 5= Poisson 6= Patterned 7= Discrete D = random number seed E = parameter of

VBA Excel Determine if “Table##” has data

北城以北 提交于 2020-01-23 01:23:07
问题 I have the following code developed to create a chart from a named Range "Table24". However, there will be times when this table has no valid data and then I want the range of my dataset to be a cell with 0 and populate the chart with no data. This is for the 4th out of 5 charts- using the debug module I've determined that this is the code which crashes my excel file everytime it's run: '//////////////////CHART 4 Creation ////////////////////////////// Set myChtRange = ws.Range("L43:R63") '

How do I concatenate cell values and text together using Excel VBA?

依然范特西╮ 提交于 2020-01-22 19:29:25
问题 I have a repetitive task I'd like to automate instead of using the =Concatenate function all the time. Here's my code so far: Cells(2, 5).Value = Cells(2, 1).Value&" - "&Cells(2, 2).Value Unfortunately this results in the "Compile error: Expected: end of statement" error, which highlights the " - ". How can I sandwich that text, " - ", between those two values? 回答1: Cells(2, 5).Value = Cells(2, 1).Value & " - " & Cells(2, 2).Value 回答2: @Joshua provided an answer for you situation. Another

Pulling Column Names into Excel from SQL query

牧云@^-^@ 提交于 2020-01-22 18:39:05
问题 I'm using Excel to pull data from an SQL db. I used the code from another SO question and it works fine. Now I want to pull in the column names from a table in addition to the actual table. I figured out that I could get the names using the For Each fld loop. However there's still the issue of populating them horizontally in a row in Excel as the number of columns might change - so I'm thinking I would need another For each loop also or something similar. Sub GetDataFromADO() 'Declare

Create Table in Excel Worksheet using VBA

独自空忆成欢 提交于 2020-01-22 15:15:20
问题 I have this code below that will auto select a range. Does anyone know how I can add code to create a table to the selected range? Thanks! Sub DynamicRange() 'Best used when first column has value on last row and first row has a value in the last column Dim sht As Worksheet Dim LastRow As Long Dim LastColumn As Long Dim StartCell As Range Set sht = Worksheets("Sheet1") Set StartCell = Range("D9") 'Find Last Row and Column LastRow = sht.Cells(sht.Rows.Count, StartCell.Column).End(xlUp).Row