I have been trying to create a macro in excel to chart a selection of data and to output the chart on the active sheet where the data was taken (as opposed to a named sheet). So basically, I have about 300 worksheets with data, and I would like to have a button on each page that automatically charts that data when clicked, and outputs the chart to the page where the macro was clicked. However, I have not been able to figure out a relative reference that will allow me to make the LocationasObject reference simply the ActiveSheet as opposed to a specifically named sheet. See my code below, which references an output to a worksheet called "Charts". Right now, all of my charts are outputting to the sheet called "Charts", as opposed to the active sheet.
Sub ConsDiscChart() ActiveCell.Offset(29, 11).Range("A1").Select Selection.End(xlToLeft).Select Selection.End(xlToLeft).Select Selection.End(xlToLeft).Select Selection.End(xlToLeft).Select Selection.End(xlToLeft).Select Selection.End(xlToLeft).Select Selection.End(xlUp).Select Selection.End(xlUp).Select Selection.End(xlUp).Select Selection.End(xlUp).Select Selection.End(xlUp).Select Selection.End(xlUp).Select Selection.End(xlDown).Select ActiveCell.Offset(0, 1).Range("A1:B1").Select Range(Selection, Selection.End(xlDown)).Select ActiveCell.Offset(0, -1).Range("A1:C24").Select Charts.Add ActiveChart.ChartType = xlLineMarkers ActiveChart.Location Where:=xlLocationAsObject, Name:="Charts" With ActiveChart .HasTitle = False .Axes(xlCategory, xlPrimary).HasTitle = False .Axes(xlValue, xlPrimary).HasTitle = False End With End Sub
I am trying to generate excel report output from access by click of a button. Part of the code is as follows:
Dim lngColumn As Long Dim xlx As Object, xlw As Object, xlc As Object Dim DBS As DAO.Database Dim rst As DAO.Recordset Dim blnEXCEL As Boolean, blnHeaderRow As Boolean
blnEXCEL = False
'If we do not want the first row we set Header to false blnHeaderRow = False
'Establish an EXCEL application object On Error Resume Next Set xlx = GetObject(, "Excel.Application")
If Err.Number <> 0 Then Set xlx = CreateObject("Excel.Application") blnEXCEL = True End If Err.Clear
I worked on development on a server and worked fine. However when I have moved the code and database to the desktop of mine I am having the following error in the line
Following bit of code runs fine if placed in Word VBA:
Code: Public Sub TaskUsageInExcel() Dim tsk As Task For Each tsk In Tasks 'Gives RTE 429 when run through Excel Debug.Print tsk.Name Next tsk End Sub
So I referenced 'Microsoft Word 12.0 Object Library' in Excel and ran the code and it gave me this error 429. Noticeable part was, no instance of word was running at that time.
So I modified the code as below:
Code: Public Sub TaskUsageInExcel2() Dim wdApp As Word.Application Dim tsk As Task
VBScript code snippet below is being used in an ASP page but the call to GetObject never attaches to a running instance of Excel. Since visible property is set to True, I can see the instances accumulate in the TaskBar each time the ASP page is called, so there are obviously instances to attach to.
Dim excelApp Set excelApp = Server.GetObject(,"Excel.Application") If (err <> 0) Then Set excelApp = Server.CreateObject("Excel.Application") End If excelApp.UserControl = True excelApp.Visible = True excelApp = Nothing
GetObject errors out with the following error: Error - Number:429 Source:Microsoft VBScript runtime error Description:ActiveX component can't create object
I have a very strange problem in DEBUG mode, because i get this error "Application-defined or object-defined error" when referring to a cell and assigning it a value so it goes to my error handler and i have a Resume Next there. It continues to go through the code whilst continuing to go to the error handler but when i step out of the function it restarts again from the beginning on the called function and then on the second run of my code it seems to WORK!?! So i'm thinking what the hell is going on, it falls over and fails the first time round and works the second time round? In free-run mode from excel i just get a #VALUE!
I have some VBA code that in one portion of it an Outlook e-mail is created and the active workbook is attached and sent. This code used to work on Excel & Outlook 2003, but now in Excel & Outlook 2007 I'm getting the error:
FY If I comment out the Set OutApp... and If OutApp.... lines and uncomment the Set OutApp create object line, I still get the same error.
Dim OutApp As Object Dim OutMail As Object Dim SigString As String Dim Signature As String
'Set OutApp = CreateObject("Outlook.Application") Set OutApp = GetObject(, "Outlook.Application") If OutApp Is Nothing Then Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0)
I have a basic data table with KPI labels down one side and dates across the top. Using this data table as the series source, I create a number of charts below it with serialised names eg Chart0, Chart1, Chart2, etc. I am attempting to enable the KPI labels so that when a user clicks it, the spreadsheet will navigate to the appropriate chart. I place the name value for the chart object in the cell immediataly to the left of each KPI label (and hide it). This way I know which chart object below is related to which KPI label above. That part works. I have a Worksheet_SelectionChange() event procedure attached to the charting worksheet. When a user clicks into one of the KPI labels, the event procedure fires and the appropriate chart is activated. The code is:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, Range("B5:B19")) Is Nothing Then On Error Resume Next chtObjName = Range(Target.Address).Offset(0, -1).Range("A1").Value If Left(chtObjName, 5) = "Chart" Then ActiveSheet.ChartObjects(chtObjName).Select If Err.Number <> 0 Then MsgBox "No such chart exists.", vbCritical, _ "Chart Not Found" End If End If On Error Goto 0 End If End Sub
whether I can handle errors in a way that tells me which object caused the error?
For example if a userform has two combobox's and one causes an error, can I return to a message box containing the name of the object (combobox1 or combobox2)?
I have tried returning err.source but I am either not using it correctly or it isn't intended to be used this way.
I am having difficulty getting a form to work the way that I would like it to work. I have a form that is used to display questions that my students will be answering. The form also is used to put the answers into a worksheet. I have 2 sheets. Sheet2 has the questions, student answers, and correct answers. Sheet1 is used to indicate correct answers and to keep track of percentage correct. I am fairly new to VB. I have 2 pieces of code that I am going to post. The first one works and the second one doesn't.
This is in the "This Workbook" section and it works. Option Explicit Public intNoQ As Integer Public strNoQ As String Public NumberofQuestions As Integer Dim StudentName As String Dim InputBoxAnswer As String Public Sub Workbook_Open() Application.Visible = False 'Hide Excel Load Questions Load NumberCorrect NumberofQuestions = Worksheets("Sheet1").Range("K3").Value For intNoQ = 1 To NumberofQuestions strNoQ = VBA.CStr(intNoQ) If intNoQ = 1 Then Questions.Controls("QuestionNumberBox").Value = "Question#" & strNoQ Questions.Controls("QuestionBox").Value = Worksheets("Sheet2").Range("B1").Value End If Questions.Controls("CorrectBox" & strNoQ).Visible = True Questions.Controls("CorrectLabel" & strNoQ).Visible = True Next intNoQ...............
I have a relatively complex report that I work with and a worksheet is no longer required. I have deleted the worksheet and reference to it hwoever when running the macro to pull all the data, it gets to the summary of all the data and i get the Run Time Error 1004 Application-defined or object-defined error pop up. ON reviewing it, it is on this line ActiveCell.Offset(0, 0).Range("a1:a" & Range_Height).Select of the below code...
VB: Sub GetRangeName() Sheets("TOTAL").Select
[Code].....
use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window.
I have a simple function below to put in different forumlas in different cells to get stock quotes. When I run this I get runtime error 1004 application-defined or object-defined error. The first formula goes through but vba chokes on the next formula: ActiveCell.Offset(I - 1, 4).Formula = username
For some reason my form won't open when the workbook is opened. I get an error message "run time error '424' object required" (which happens when I have Form1.show in the BOTH workbook_open event and the userform_initialize event (oops)). When I removed form1.show from the userform_initialize I don't get an error but I also get no form. I recall having this issue before but I can't recall how to fix it.
Can I call the userform_initialize event from the workbook open event to get around this successfully and properly?
I am trying to copy the info from one workbook to another workbook.
I keep getting the above referenced error...
Private Sub CommandButton1_Click() Dim filepath As String filepath = Range("A100") MsgBox ("File Appended") Workbooks.Open (filepath) Windows("CorrespondenceMaster.xls").Activate Sheets("Sheet2").Select Range("DesNo", "LocationPath").Select Selection.Copy Windows(filepath).Activate Range("A2").Select ActiveSheet.Paste End Sub
I copied a routine from this forum that would email a single sheet from a 10-sheet workbook to a recipient. This worked great for a long time, then all of a sudden I started getting the "ActiveX control can't create object" error. Here is my
I'm trying to open a file and perform various tasks. This is the structure:
Dim xlApp As Object Dim xlWb As Object
Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlWb = xlApp.Workbooks.Open(BackupFile) ' backupfile evaluates to c: esting est.xls xlWb.Worksheets(1).Activate
Debug.Print xlWb.Worksheets.Count Dim ws As Worksheet For Each ws In xlWb.Worksheets Debug.Print ws.Name ws.Activate Next ws I think I'm totally missing something. The above works, except for the loop. None of the names show up in my immediate window, and none of the worksheets are activated. xlWB evaluates to nothing, which is where the problem has to be...but why would my first .Activate and Debug.Print lines work? Also, If I declare xlWb as Workbook then absolutely nothing works after the file is opened.
Basically what I want to do is open the file, do a bunch of a stuff with it, then save and close it. I have this all working without creating another object, but the opening of the file is still visible to the user. Seems like turning off ScreenUpdating doesn't truly work.
I want to create a macro to open a webpage, and with that webpage fill out the fields on the webpage and then hit enter and move to next record. I am having great difficulties with establishing Internet Explorer as my object and maneuvering around inside of it. My data would being in column A so i would expect to use the string below when referencing my data.
Do Until Workbooks(2).Worksheets(1). Range("A" & row) = ""
I am trying to make this code work, I am getting the subject error:
HTML Code: Private Sub CommandButton1_Click()Dim cols As VariantDim NextRow As ObjectDim Myrow As Object Sheets("Sheet1").SelectWith Sheet1 Myrow = Range("A" & Rows.Count).End(xlUp).Row + 1
Sub Macro2() ' ' Macro2 Macro ' Macro recorded 7/28/2007 by i8ig '
If Target.Column = 1 Then If Target.Value = "Med" Then Rows(Target.Row).Interior.ColorIndex = 4 Range("H3").Select ActiveCell.FormulaR1C1 = "=IF(RC[3]="""","""",RC[3]-3)" Else If Target.Value = "Tasc" Then Rows("4:4").Interior.ColorIndex = 44 Range("H4").Select ActiveCell.FormulaR1C1 = "=IF(RC[1]="""","""",RC[1]-2)" Else If Target.Range = "NBAR" Then Range("J5").Select ActiveCell.FormulaR1C1 = "=IF(RC[1]="""","""",RC[1]-5)" Range("I5").Select ActiveCell.FormulaR1C1 = "=IF(RC[1]="""","""",RC[1]-2)" Range("H5").Select ActiveCell.FormulaR1C1 = "=IF(RC[1]="""","""",RC[1]-2)" End If End If End If End If End Sub I continue to receive an error '424' object required and I cant find it
I have two worksheets one called "invoice" and one called "tenants" "Invoice" has a userform where I want to enter a tenancy number and then lookup the tenants name and address from "tenants"
I have put the following macro in
Sub lookup() Dim res As Variant res = Application.VLookup("A1", Tenants.xlsx("Sheet1"), "$A:$H", 2, False) If IsError(res) Then MsgBox "not found" Else MsgBox "found at pos: " & res End If End Sub
I am trying to get the code to search for me specific words in the excel files in my Folder as specified, however when i try to run it, there will be a Error 424 : Object required.
Sub SearchText()
cr = vbCrLf quot = Chr(34) 'quotes
Dim l As FileSearch Set l = Application.FileSearch
s = InputBox("Search", " Enter the text you're looking for.")
With l .NewSearch .LookIn = "D:FinancialNews" .SearchSubFolders = True .FileName = "*.xls" .MatchTextExactly = True ............................
I am trying to name a dynamic range. The below works when I have selected the relevant sheet. However, if the sheet is not selected then I get a Runtime Error 1004 at the Else line. I had planned on naming 3 ranges like this on each sheet. I have 15 sheets, so end result will be 45 ranges.
Sub CIT_SLA() 'Name and size the range CIT_SLA so the Word file (EOM Report) can pick only the relevant cells If Sheets("CIT Results").Range("A2").Value = "" Then Sheets("CIT Results").Range("A2:G2").Name = "CIT_SLA"
Else: Sheets("CIT Results").Range("A2", Range("G65536").End(xlUp)).Name = "CIT_SLA" End If
Sub Test(ByRef objRange As Range) objRange.Value = "Hi" End Sub
Sub TestTheTestMethod() With ThisWorkbook. Sheets("Sheet1") Set objRange = .Range(.Cells(1, 1), .Cells(i - 1, 3)) objRange.Value = "Hi" 'This works fine ! Test (objRange) 'But here... Getting ERROR 424 -- Object Required End With End Sub