Search Results

Search found 1188 results on 48 pages for 'vba'.

Page 14/48 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • How to use VBA to colour pie chart

    - by Timon Heinomann
    I have the following code in which the code tries to create a bubble chart with pie charts as the bubbles. As in this version colour themes are used to create a different colour in each pie chart (bulbble) in the function part I have the problem that it works depending on the paths to the colour paletts. Is there an easy way to make the function in a way that it works independently of those paths either by coding a colour for each pie chart segment or by using standardize paths (probably not possible, not preferable). Sub PieMarkers() Dim chtMarker As Chart Dim chtMain As Chart Dim intPoint As Integer Dim rngRow As Range Dim lngPointIndex As Long Dim thmColor As Long Dim myTheme As String Application.ScreenUpdating = False Set chtMarker = ActiveSheet.ChartObjects("chtMarker").Chart Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart Set chtMain = ActiveSheet.ChartObjects("chtMain").Chart Set rngRow = Range(ThisWorkbook.Names("PieChartValues").RefersTo) For Each rngRow In Range("PieChartValues").Rows chtMarker.SeriesCollection(1).Values = rngRow ThisWorkbook.Theme.ThemeColorScheme.Load GetColorScheme(thmColor) chtMarker.Parent.CopyPicture xlScreen, xlPicture lngPointIndex = lngPointIndex + 1 chtMain.SeriesCollection(1).Points(lngPointIndex).Paste thmColor = thmColor + 1 Next lngPointIndex = 0 Application.ScreenUpdating = True End Sub Function GetColorScheme(i As Long) As String Const thmColor1 As String = "C:\Program Files\Microsoft Office\Document Themes 15\Theme Colors\Blue Green.xml" Const thmColor2 As String = "C:\Program Files\Microsoft Office\Document Themes 15\Theme Colors\Orange Red.xml" Select Case i Mod 2 Case 0 GetColorScheme = thmColor1 Case 1 GetColorScheme = thmColor2 End Select End Function The code copies a single chart again and again on the bubbles. So I woudl like to alter the Function (now called Get colourscheme) into a fucntion that assigns a a unqiue rgb colour to each segment of each pie chart

    Read the article

  • Excel VBA pass array of arrays to a function

    - by user429400
    I have one function that creates an array of arrays, and one function that should get the resulting array and write it to the spreadsheet. I don't find the syntax which will allow me to pass the array of arrays to the second function... Could you please help? Here is my code: The function that creates the array of arrays: Function GetCellDetails(dict1 As Dictionary, dict2 As Dictionary) As Variant Dim arr1, arr2 arr1 = dict1.Items arr2 = dict2.Items GetCellDetails = Array(arr1, arr2) End Function the function that writes it to the spreadsheet: Sub WriteCellDataToMemory(arr As Variant, day As Integer, cellId As Integer, nCells As Integer) row = CellIdToMemRow(cellId, nCells) col = DayToMemCol(day) arrSize = UBound(arr, 2) Range(Cells(row, col), Cells(row + arrSize , col + 2)) = Application.Transpose(arr) End Sub The code that calls the functions: Dim CellDetails CellDetails = GetCellDetails(dict1, dict2) WriteCellDataToMemory CellDetails, day, cellId, nCells Thanks, Li

    Read the article

  • how do i declare a global variable in VBA

    - by Nimrod
    I wrote the following section: Function find_results_idle() Public iRaw As Integer Public iColumn As Integer iRaw = 1 iColumn = 1 and i get the error messege: "invalid attribute in Sub or Function" do you know what i did wrong? i tried instead of "Public" to use "Global" but got the same problem. I tird to declare the function itself as "Public" but no good... what do i do wrong? thanks.

    Read the article

  • Export sheet from Excel to CSV

    - by Mike Wills
    I am creating a spread sheet to help ease the entry of data into one of our systems. They are entering inventory items into this spread sheet to calculate the unit cost of the item (item cost + tax + S&H). The software we purchased cannot do this. Aan invoice can have one or more lines (duh!) and I calculate the final unit cost. This is working fine. I then want to take that data and create a CSV from that so they can load it into our inventory system. I currently have a second tab that is laid out like I want the CSV, and I do an equal cell (=Sheet!A3) to get the values on the "export sheet". The problem is when they save this to a CSV, there are many blank lines that need to be deleted before they can upload it. I want a file that only contains the data that is needed. I am sure this could be done in VBA, but I don't know where to start or know how to search for an example to start. Any direction or other options would be appreciated.

    Read the article

  • Weird bug on powerpoint vba

    - by asksuperuser
    I have a "mynote" textbox on a slide. If I execute: Sub test() If ActiveWindow.Selection.SlideRange.Shapes("mynote").Visible Then MsgBox "ok" End If end sub It works. But If I attach a shape with this macro: Sub test(oShape As Shape) If ActiveWindow.Selection.SlideRange.Shapes("mynote").Visible Then MsgBox "ok" End If end sub It doesn't work (no error message, no "ok" message)

    Read the article

  • Excel VBA / SQL Union

    - by Edge
    Hi, I am trying to Join 2 seperate columns from 2 different sheets to make a longer column from which i can then use a Vlookup from. Sheet1 A, B, C, D, E, F, G Sheet2 A, B, C, D, E, F, G I want to Join(Union) Columns B from sheet1 and C from sheet2 together and find the Distinct values of the new list. I have been working on this for weeks. Thanks

    Read the article

  • VBA form_error vs on error

    - by dmr
    I am trying to set up error handling for a MS-Access application. The standard method to do this seems to be with an On Error statement in each subroutine/function. It seems simpler to me to use the Form_Error function to catch all the runtime errors in that form as opposed to an On Error statement for each sub/function called by an event on that form. (Obviously, for code in modules, there is no Form_Error function and therefore the only method is the On Error statement) What are the pros and cons of using On Error vs Form_Error?

    Read the article

  • vba: a forever loop

    - by I__
    Sub something(tecan) On Error Resume Next Dim arr As New Collection, a Dim aFirstArray() As Variant Dim i As Long aFirstArray() = Array(Dir(tecan & "*.ESY", vbNormal)) aFirstArray(0) = Mid(aFirstArray(0), 1, 4) Do While Dir <> "" ReDim Preserve aFirstArray(UBound(aFirstArray) + 1) aFirstArray(UBound(aFirstArray)) = Mid(Dir, 1, 4) Loop On Error Resume Next For Each a In aFirstArray arr.Add a, a Next For i = 1 To arr.Count Cells(i, 1) = arr(i) 'open_esy (tecan & arr(i) & "*") Next Erase aFirstArray For i = 1 To arr.Count arr.Remove i Next i here is how i call this sub: something (tecan1) something (tecan2) on the first call it works and does what it is supposed to but on the second call it gets stuck in this loop: Do While Dir <> "" ReDim Preserve aFirstArray(UBound(aFirstArray) + 1) aFirstArray(UBound(aFirstArray)) = Mid(Dir, 1, 4) Loop why does it get stuck in the loop?

    Read the article

  • WHERE IN Query with two recordsets in Access VBA

    - by Henry Owens
    Hi All, My first post here, so i hope this is the right area. I am currently trying to compare 2 recordsets, one of which has come from an Excel named range, and the other from a table in the Access database. The code for each is: Set existingUserIDs = db.OpenRecordset("SELECT Username FROM UserData") Set IDsToImport = exceldb.OpenRecordset("SELECT Username FROM Named_Range") The problem is that I would like to somehow compare these two recordsets, without looping (there is a very large number of records). Is there any way to do a join or similar on these recordsets? I can not do a join before creating the recordsets, due to the fact that one is coming from Excel, and the other from Access, so they are two different DAO databases. The end goal is that I will choose only the usernames that do not already exist in the access table to be imported (so in an SQL query, it would be a NOT IN(table)). Thanks for any assistance you can lend! Regards, Bricky.

    Read the article

  • VBA Add to Array and Use Previous Value

    - by MattHead93
    I'm trying to write some code that will take a value WeekNum, and add it to an array Week(1 To 51), and then associate a value from a Textbox TargDef. Once this has been added to the array, I want to look up the value of the array for the previous WeekNum and add it to a value ProdTarg. I've created this much so far: Dim Week(1 To 51) Dim Count As Integer If TargDef < 0 Then Count = WeekNum Week(Count) = Abs(Val(TargDef)) If Val(Week((Count) - 1)) = 0 Then ProdTarg = Val(ProdTarg) Else ProdTard = Val(ProdTarg) + Val(Week((Count) - 1)) End If End If I am currently receiving the error "Subscript out of Range" for the line If Val(Week((Count) - 1)) = 0 Then Any help will be greatly appreciated!

    Read the article

  • Exporting emails from outlook programtically with vba

    - by David
    I'm using this script to export email from outlook. My question is how do I export the body of the email without the html formatting ? Sub SaveItemsToExcel() On Error GoTo ErrorHandlerExit Dim oNameSpace As Outlook.NameSpace Dim oFolder As Outlook.MAPIFolder Dim objFS As Scripting.FileSystemObject Dim objOutputFile As Scripting.TextStream Set objFS = New Scripting.FileSystemObject Set objOutputFile = objFS.OpenTextFile("C:\Temp\Export.csv", ForWriting, True) Set oNameSpace = Application.GetNamespace("MAPI") Set oFolder = oNameSpace.PickFolder If oFolder Is Nothing Then GoTo ErrorHandlerExit End If If oFolder.DefaultItemType <> olMailItem Then MsgBox "Folder does not contain mail messages" GoTo ErrorHandlerExit End If objOutputFile.WriteLine "From,Subject,Recived, Body" ProcessFolderItems oFolder, objOutputFile objOutputFile.Close Set oFolder = Nothing Set oNameSpace = Nothing Set objOutputFile = Nothing Set objFS = Nothing ErrorHandlerExit: Exit Sub End Sub Sub ProcessFolderItems(oParentFolder As Outlook.MAPIFolder, ByRef objOutputFile As Scripting.TextStream) Dim oCount As Integer Dim oMail As Outlook.MailItem Dim oFolder As Outlook.MAPIFolder oCount = oParentFolder.Items.Count For Each oMail In oParentFolder.Items If oMail.Class = olMail Then objOutputFile.WriteLine oMail.SenderEmailAddress & "," & Replace(oMail.Subject, ",", "") & "," & oMail.ReceivedTime End If Next oMail Set oMail = Nothing If (oParentFolder.Folders.Count > 0) Then For Each oFolder In oParentFolder.Folders ProcessFolderItems oFolder, objOutputFile Next End If End Sub

    Read the article

  • vba Loop over a non-contiguous range

    - by Jeffrey
    I have a non-contiguous range on rows (example address of myRange: $2:$2,$4:$205,$214:$214) and I would like to access a specific row and column within the range. I have tried the following: 'Get the value of the 2nd row, 1st column within the range myRange.rows(2).Cells(, 1).Value However, this is giving me the value of the 2nd row in the WorkSheet, and NOT in the range - meaning it is giving me address $3$1 - and not $4$1 Can someone please explain how I can access the values within in my range? (It may have to do with different areas) Thank You

    Read the article

  • vba excel copy subtable from sheet to sheet

    - by user429400
    I realize that this is probably a duplicate, but I've been searching for an hour and I can't to get the syntax right. I have a sheet with several tables. There is at least one empty column and one empty row between one table to the other. I know the start row and start column of each table, and I know that each table has 3 columns. I don't know how many rows it has. I want to write a sub that receives: table start row table start column and copies the table into another sheet (let's say that the destination is sheet2 starting at A1). I know I can do it with a loop, but I suspect there is a better syntax right? (The main issue here is that I need to find the number of rows each table has) Thanks. Li

    Read the article

  • Execute VBA Macro via C# Interop?

    - by Jon Artus
    Hi all, just wondering if anyone could suggest why I might be getting an error? I'm currently trying to execute a macro in a workbook by calling the Application.Run method that the interop exposes. It's currently throwing the following COM Exception: {System.Runtime.InteropServices.COMException (0x800A03EC): Cannot run the macro Macro1'. The macro may not be available in this workbook or all macros may be disabled. I've put the containing workbook in a trusted location, set all of the security settings to their minimum values, and trusted programmatic access to my object model. I'm entirely out of ideas and Google's failed me so far! Has anyone done this, or can you suggest anything which I could try? Many thanks!

    Read the article

  • Excel 2010 VBA code is stuck when UserForm is shown

    - by Denis
    I've created a UserForm as a progress indicator while a web query (using InternetExplorer object) runs in the background. The code gets triggered as shown below. The progress indicator form is called 'Progerss'. Private Sub Worksheet_Change(ByVal Target As Range) If Target.Row = Range("B2").Row And Target.Column = Range("B2").Column Then Progress.Show vbModeless Range("A4:A65535").ClearContents GetWebData (Range("B2").Value) Progress.Hide End If End Sub What I see with this code is that the progress indicator form pops up when cell B2 changes. I also see that the range of cells in column A gets cleared which tells me that the vbModeless is doing what I want. But then, somewhere within the GetWebData() procedure, things get hung up. As soon as I manually destroy the progress indicator form, the GetWebData() routine finishes and I see the correct results. But if I leave the progress indicator visible, things just get stuck indefinitely. The code below shows what GetWebData() is doing. Private Sub GetWebData(ByVal Symbol As String) Dim IE As New InternetExplorer 'IE.Visible = True IE.navigate MyURL Do DoEvents Loop Until IE.readyState = READYSTATE_COMPLETE Dim Doc As HTMLDocument Set Doc = IE.document Dim Rows As IHTMLElementCollection Set Rows = Doc.getElementsByClassName("financialTable").Item(0).all.tags("tr") Dim r As Long r = 0 For Each Row In Rows Sheet1.Range("A4").Offset(r, 0).Value = Row.Children.Item(0).innerText r = r + 1 Next End Sub Any thoughts?

    Read the article

  • Excel pivot refresh, save and close in Access VBA code

    - by schneidm
    I am using the following code to refresh Excel pivot tables from an Access application. What is the best way to save and close the Excel app after the pivots refresh? In my last attempt the code was trying to save and close before the pivots had refreshed. Private Sub Command161_Click() Dim objXL As Object, x On Error Resume Next Set objXL = CreateObject("Excel.Application") With objXL.Application .Visible = True 'Open the Workbook .Workbooks.Open "myfilepath.xls" 'Refresh Pivots x = .ActiveWorkbook.RefreshAll End With Set objXL = Nothing End Sub

    Read the article

  • Access VBA question: Change the query being referenced by a function, depending on context

    - by Tara Amatista
    I have a custom function in Access2007 that hinges on grabbing data out of a specific query. It opens Outlook, creates a new email and populates the fields with specific addresses and data taken from the query ("DecisionEmail"). Now I want to make a different query ("RequestEmail") and have it populate the email with that data. So all I have to do is change this line: Set MailList = db.OpenRecordset("DecisionEmail") and that's where I get stumped. This is my desired result: If the user is on Form_Decision and clicks the button "Send email", "DecisionEmail" will get plugged into the function and that data will appear in the email. If the user on Form_SendRequest and clicks the button "Send email", "RequestEmail" will instead get plugged in. The reason that these are different queries is because they contain very different information that is smudged about in different ways. However, since it's just one little thing that needs to change in the function code, I don't think a brand new function is a good idea. My last resort would be to make a brand new function and use the Conditions field in the Macro interface to choose between them, but I have a feeling there's a more elegant solution possible. I have a vague notion of setting the query names as variables and using an If statement but I just don't have the mental vocabulary for thinking through this.

    Read the article

  • Splitting a string with variable number of spaces VBA

    - by GVBA
    I have a file with a bunch of number in columns. These numbers are separated by variable number of spaces. I want to skip the first line and get all the other lines and separte each number on the line. Finally, I want to write each number on Excel. I've been able to get the lines and write them on Excel but I can't separate each number (I'm getting the whole line as one string). Does any body know how to split a string that has a variable number of spaces? Here is my code. Sub Test() r = 0 With New Scripting.FileSystemObject With .OpenTextFile("C:\Users\User\Desktop\File.tab", ForReading) If Not .AtEndOfStream Then .SkipLine Do Until .AtEndOfStream ActiveCell.Offset(r, 0) = Split(.ReadLine, vbCrLf) r = r + 1 Loop End With End With End Sub

    Read the article

  • FTP a text file to a server using VBA in Excel

    - by Anindya
    I have an Excel worksheet where the user enters certain data, which I want to store in a text file and upload to a server using FTP. One site suggested adding a reference to "Microsoft Internet Transfer Control" and then define an "Inet" object to do the FTP. However, I am unable to find a reference with this name in "Tools - References" in the VB Editor. Does anyone know of a solution for this problem? Thanks in advance.

    Read the article

  • Need a piece of advice about e-mail automation in ms exchange + ms office environment

    - by be here now
    Hi, guys. I need your help in the following simple situation. I've got an MS Exchange server and some client computers running on XP with Office 2003 installed. And I've got a process I need to automate. Twice a day a known list of people sends an e-mail to a certain mailbox (let's call it manager's mailbox) - basically, an accomplishment report. After recieving letters from all of these people the mailbox owner sends and e-mail to another mailbox, meaning that a certain process is done. What I need to do is to replace this manager's mailbox with a depersonalized mailbox that will accumulate all the reports and automatically send a message after collecting all of them. I am definitely not in a "oh my God, what shold I do?" situation, and currently my imagination shows me a couple of ways to solve this problem, which I'm going to try, and I'm not ascking for a ready solution. But since I'm not experienced in Office/VBA developement, I'd like to ask a corresponding pro's opinion. Can you point me to a right direction from the best practices' point of view?

    Read the article

  • VBA-Excel return multidimensional array from a function

    - by alesdario
    I'm trying to write a function which returns a multidimensional array. The problem is that the size of the array isn't defined. My array is initialized in the function below my_list() Dim my_list() As String Public Sub Load_My_List() Dim last_column As Integer last_column = some_helper.Get_Last_Column(somw_worksheet) 'my array is resized in this point ReDim my_list(1 To last_column - 1, 1) Dim i As Integer i = 1 For index= 2 To ultima_colonna my_list(i, 0) = some_worksheet.Cells(2, index).value my_list(i, 1) = index i = i + 1 Next index End Sub So, how can i write a function which returns my_list ? Something like the function below generate a mismacthing type error Public function Get_My_List as String() Get_My_List = my_list End Function and how can i call this function properly? I think that something like Dim test() as String test = Get_My_List will doesn't work

    Read the article

  • Grabbing "last saved by" metadata from access '03 file to excel '03 in VBA

    - by Spacious
    So I am in Excel trying to read the last saved metadata from an Access database, but I cannot figure out how on earth to do this. If I use environ$("username") it will give my the last saved information for the excel document where I am coding, not the access db that I want it to grab from. Excel has a built in function for grabbing username data, but I cannot find one for access. How can I do this?! Any help is greatly appreciated!

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >