Re: Student maths practice - check answers, count #correct and more
Looking forward to it, I've been following this thread with interest.
Re: Student maths practice - check answers, count #correct and more
Looking forward to it, I've been following this thread with interest.
Re: open an excel file and insert a row with data on it then close it back
Provided that when you say dBase File you actually mean the Excel Binary File (as opposed to something like an actual Access Database) then yes.
It's the full code that I created sometime back for standardising the opening of workbooks. So on my system it sits in a separate excel add-in (.xlam) that can be referenced from any code that I write so I don't have to bother coding the opening of sheets every time.
So the only mandatory variable that needs passed into it is the full file path, all the others are optional around the type of access you need.
Depending on what's passed into it, it will attempt to open the file, check that access it has against what you requested and either fire an error message confirming that it can't meet your requested access requirements just now (you need write access and someone is locked to it limiting you to read access for the moment being the main issue), or the file is opened as requested.
The last variable/object allows you to pass an actual workbook object as well, if this is supplied then it will set that object for you before passing it back to your calling code, at which point you can refer to the newly opened workbook as that object, rather than having to mess about with the full file path.
To be honest I'd probably tidy things up a bit if I did it again now, but it should still be fit for purpose.
The idea for you is not to worry too much about it, but just drop it in a new module in your project, call it from your code and give it the appropriate variables and objects. It should hopefully just work without you having to worry too much about what is going on, although I accept you don't know me and probably want to be sure I'm not stealing your bank details or some other nefarious scheme.
Re: Hide entire row based on value of one cell
I'd guess you want to fire the code on request rather than happening in realtime, so for that you'd need some sort of interface for the user (ActiveX button probably, or possibly checkbox, when ticked filter the sheet, when unticked display all).
That aside, shouldn't be too difficult to achieve.
A pretty simple piece of code would be something like:
Public Sub HideDRows(ByRef wsTemp As Worksheet) 'Assume that as you want to call this from other workbooks the worksheet would be provided to the code
Dim lngRefColumn As Long: lngRefColumn = 13 'Set to Column 13, or M
Dim lngStartRow As Long: lngStartRow = 2 'I'm assuming your data starts on the second row
Dim lngEndRow As Long: lngEndRow = GetLastRow(wsTemp, lngRefColumn) 'Use the Worksheet and Reference Column to find the last row
Dim lngWrkRow As Long
For lngWrkRow = lngStartRow To lngEndRow
If Trim(wsTemp.Cells(lngWrkRow, lngRefColumn)) = "D" Then
wsTemp.Rows(lngWrkRow).EntireRow.Hidden = True
Else
wsTemp.Rows(lngWrkRow).EntireRow.Hidden = False
End If
Next lngWrkRow
End Sub
'Gets the last populated row based on the worksheet and column supplied
Private Function GetLastRow(ByRef wsTemp As Worksheet, ByRef lngColumn As Long) As Long
With wsTemp
GetLastRow = .Cells(.Rows.Count, lngColumn).End(xlUp).Row
End With
End Function
Display More
Worth bearing in mind though that's only going to hide the rows. And requires some code before hand to get the appropriate sheet in order for this to be passed to the HideDRows routine.
If you want the rows displayed again then you'd need some way of tracking and toggling the setting, or having two buttons, one to perform the hiding and another just to show all rows again (although that can be done pretty easily from the sheet as well).
Hope that helps and at least gets your started.
Re: Computing Index/Match using data from another worksheet
I'd guess your compile error is connected to the LastRow step.
Having the period in front of the Cells property suggests that you've defined the worksheet beforehand, i.e.
So given the other two are I believe referencing the same worksheet I'd probably go with:
Re: Simpying Repetitive Macro Codes
Oh my. That seems inefficient.
Private Sub CheckBox1_Click()
Call GenericCheckBoxBehaviour(chkBoxObject)
End Sub
Private Sub GenericCheckBoxBehaviour(byref chkBoxObject as Checkbox)
Dim wsTarget As Workbook
Dim wsSource As Workbook
Dim rngSource As Range
Dim rngTarget As Range
Dim wbname As String
With Excel.Application
.ScreenUpdating = False
.Calculation = Excel.xlCalculationManual
End With
wbname = "C:\\My Documents\Blotter\Master.xlsm"
Set wsSource = ActiveWorkbook
Set wsTarget = Workbooks.Open(wbname)
Worksheets("Master").Select
Worksheets("Master").Range("B6").Select
Set rngSource = wsSource.Sheets("Blotter").Range("B7:O7")
Set rngTarget = Worksheets("Master").Range("B" & (Worksheets("Master").Range("B65536").End(xlUp).Row + 1))
If chkBoxObject.Value = True Then
rngSource.Copy
rngTarget.PasteSpecial xlPasteValues
wsSource.Worksheets("Blotter").Activate
End If
wsTarget.Close True
With Excel.Application
.ScreenUpdating = True
.Calculation = Excel.xlAutomatic
.CutCopyMode = False
End With
End Sub
Display More
Only the top part is needed for each checkbox if the rest of the behaviour is generic
Re: Deleting Groups of Like Rows where a no negative value exists in a specific colum
You're welcome, glad to help.
Re: Codes run slower
All your steps are interacting directly with the sheet which depending on the size of the ranges you are dealing with it can get pretty sluggish.
I've got no idea from looking at your code what it is you're actually trying to do but if you want to improve efficiency my first suggestion would be to split your process into three parts.
1. Extract Input Data from the spreadsheet into memory (objects & variables)
2. Perform the required processes to the data to create the output in memory
3. Package the output up and return the output data to the worksheet
It can take a little bit of getting used to as you can't see the things happening on the sheet in real-time, but it's a lot faster at processing this way. Just means you need to make a lot more use of the Immediate and Watch windows in the VBA Win
Re: Deleting Groups of Like Rows where a no negative value exists in a specific colum
Quote from nilem;798791Hi DGWin,
try itCodeDisplay MoreSub ertert() Dim x, y(), i&, s$, k& With Sheets("Sheet1") x = .Range("A1:E" & .Cells(Rows.Count, 2).End(xlUp).Row + 1).Value End With ReDim y(1 To UBound(x), 1 To 2) For i = 1 To UBound(x) If x(i, 2) <> s Then s = x(i, 2) k = k + 1 Set y(k, 1) = Cells(i, 2) If x(i, 5) > 0 Then y(k, 2) = "del" Else Set y(k, 1) = Union(y(k, 1), Cells(i, 2)) If x(i, 5) < 0 Then y(k, 2) = "" End If Next i For i = k To 1 Step -1 If y(i, 2) = "del" Then y(i, 1).EntireRow.Delete Next i End Sub
Pretty similar solution although admittedly more compact.
I unfortunately have the company standards embedded into everything I produce now. Hence the far larger bit of code doing essentially the same thing.
Re: Deleting Groups of Like Rows where a no negative value exists in a specific colum
Okay give this one a bash, hopefully I've understood your requirements correctly now.
Option Explicit
'Loops through a defined range and deletes entire row where a value > 0 is found in column 3
Public Sub DeletePositiveRows()
Dim wsTemp As Worksheet: Set wsTemp = ThisWorkbook.Sheets("OutputSummary")
Dim lngItemCol As Long: lngItemCol = 2
Dim lngValueCol As Long: lngValueCol = 3
Dim lngStartRow As Long: lngStartRow = 2
Dim lngEndRow As Long: lngEndRow = GetLastRow(wsTemp, lngItemCol) 'Bases the end row on the contents of Column B (2)
Dim lngWrkRow As Long
Dim lngGroupStart As Long
Dim lngGroupEnd As Long
Dim strCurrentGroupItem As String
Dim blnDeleteGroup As Boolean
Dim colRowCollection As Collection
With wsTemp
'Set the starting values
lngWrkRow = lngStartRow
Set colRowCollection = New Collection
Do
'First loop handles each item group
lngGroupStart = lngWrkRow
blnDeleteGroup = True
strCurrentGroupItem = .Cells(lngWrkRow, lngItemCol)
Do
'Second loop handles the items within the group
'Move through the group and check if any items are greater than zero
If .Cells(lngWrkRow, lngValueCol) < 0 Then
'If an item is found greater than zero set the flag to mark it for deletion
blnDeleteGroup = False
End If
lngWrkRow = lngWrkRow + 1
Loop Until strCurrentGroupItem <> .Cells(lngWrkRow, lngItemCol) 'Exits when it reaches the end of the current group
lngGroupEnd = lngWrkRow - 1
If blnDeleteGroup = True Then Call AppendToDeleteCollection(lngGroupStart, lngGroupEnd, colRowCollection)
Loop Until lngWrkRow > lngEndRow
'Check if any groups have been flagged for deletion and delete them if they are
If colRowCollection.Count > 0 Then Call DeleteRowsFromCollection(wsTemp, colRowCollection)
End With
End Sub
'Gets the last populated row to set the limits of the loop
Private Function GetLastRow(ByRef wsTemp As Worksheet, ByRef lngColumn As Long) As Long
With wsTemp
GetLastRow = .Cells(.Rows.Count, lngColumn).End(xlUp).Row
End With
End Function
'Adds all the rows in an item group to the collection to be deleted at the end
Private Sub AppendToDeleteCollection(ByRef lngGroupStart As Long, ByRef lngGroupEnd As Long, ByRef colRowCollection As Collection)
Dim lngCounter As Long
For lngCounter = lngGroupStart To lngGroupEnd
colRowCollection.Add lngCounter
Next lngCounter
End Sub
Private Sub DeleteRowsFromCollection(ByRef wsTemp As Worksheet, ByRef colRowCollection As Collection)
Dim lngItemNumber As Long
Dim lngRowNumber As LoadPictureConstants
'Delete the rows in reverse order to avoid having to deal with them shifting and knocking the references out
With wsTemp
For lngItemNumber = colRowCollection.Count To 1 Step -1
lngRowNumber = colRowCollection.Item(lngItemNumber)
.Rows(lngRowNumber).EntireRow.Delete
Next lngItemNumber
End With
End Sub
Display More
Same as before, change the sheet reference name accordingly for your workbook.
Couple of things to note. This is still interacting with the sheet directly. If it's not a large file then it's probably not an issue, but if it is a large dataset you are dealing with the performance would be greatly improved by taking the data off the sheet completely, evaluating it in memory and then returning the results to the sheet, that way you only need to interact directly with the sheet twice.
Secondly, this method relies on the data being ordered by the items, if your items are not all grouped together then it would treat the two lots of the same item as two distinct groups and evaluate them individually (again this is something that could be addressed by taking the data into memory first.
This could all be done quite easily but it is extra work and only really needed if your data isn't grouped or it's a large dataset and you want to improve efficiency.
Re: Late Binding an Object based on its Type after being set
*Heads off to read up on interface classes*
Re: open an excel file and insert a row with data on it then close it back
This may help you (although maybe a lengthy solution). It's all the code for an add-in I had written a while back to handle opening other workbooks where different access may be required (saved me rewriting the same thing every time I needed a bespoke solution).
Option Explicit
'Provides access to the file path provided
Sub A_ExternalWorkbookAccess(ByRef strFullPath As String, _
Optional ByRef blnWriteAccessRequired As Boolean = False, _
Optional ByRef blnSuppressAlreadyOpenMsg As Boolean = False, _
Optional ByRef blnSuppressEvents As Boolean = False, _
Optional ByRef blnUpdateLinks As Boolean = False, _
Optional ByRef blnReadOnly As Boolean = True, _
Optional ByRef strPassword As String = vbNullString, _
Optional ByRef strWriteResPassword As String = vbNullString, _
Optional ByRef varTargetWorkbook As Variant)
Dim strFilePathCheckMsg As String
Dim wbTargetWorkbook As Workbook
Dim blnWorkbookOpened As Boolean
Dim blnCurrentEvents As Boolean
Dim blnCurrentUpdating As Boolean
'Gets current EnableEvents/ScreenUpdating values to reapply before handing control back to calling routines
blnCurrentEvents = Application.EnableEvents
blnCurrentUpdating = Application.ScreenUpdating
'Turns both off before process starts
Application.EnableEvents = False
Application.ScreenUpdating = False
'Checks the validity of the File Path String
strFilePathCheckMsg = B_ValidFilePathCheck(strFullPath)
If strFilePathCheckMsg <> "Path Exists" Then Call A_FilePathError(strFullPath, strFilePathCheckMsg, blnCurrentEvents, blnCurrentUpdating)
'Check if the workbook is already open
If B_CheckForOpenWorkbook(strFullPath, wbTargetWorkbook, blnCurrentEvents, blnCurrentUpdating) = True Then
'Checks request against opened file permissions
Call A_WriteAccessChecks(blnWriteAccessRequired, wbTargetWorkbook, strFullPath, blnCurrentEvents, blnCurrentUpdating)
'Checks if the "Sheet Open" message has been suppressed
If blnSuppressAlreadyOpenMsg = False Then
MsgBox "The Workbook is already open in this application", vbCritical, "Workbook Open Error"
End If
Else
'Sends the request to open the file
Call A_OpenFile(wbTargetWorkbook, blnSuppressEvents, blnUpdateLinks, blnReadOnly, strPassword, strWriteResPassword, strFullPath)
'Checks request against opened file permissions
Call A_WriteAccessChecks(blnWriteAccessRequired, wbTargetWorkbook, strFullPath, blnCurrentEvents, blnCurrentUpdating)
End If
If IsMissing(varTargetWorkbook) = False Then Set varTargetWorkbook = wbTargetWorkbook
'Returns ScreenUpdating and EnableEvents back to their starting value
'before returning control to the calling routine
Application.ScreenUpdating = blnCurrentUpdating
Application.EnableEvents = blnCurrentEvents
Set wbTargetWorkbook = Nothing
End Sub
'File Path error handler
'Called when there is an issue with the file path, the appropriate error message is supplied with the call
Private Sub A_FilePathError(ByRef strFullPath As String, _
ByRef strFilePathCheckMsg As String, _
ByRef blnCurrentEvents As Boolean, ByRef blnCurrentUpdating As Boolean)
Dim strMsgBoxContent As String
'Controls the dynamic section of the error message
If strFilePathCheckMsg = "No file path has been supplied" Then
strMsgBoxContent = "The following issue has been detected:" _
& vbNewLine & vbNewLine & _
" - " & strFilePathCheckMsg _
Else
strMsgBoxContent = "You have supplied the following file path:" _
& vbNewLine & vbNewLine & _
strFullPath _
& vbNewLine & vbNewLine & _
"The following issue was detected with this file path:" _
& vbNewLine & vbNewLine & _
" - " & strFilePathCheckMsg
End If
'Adds the generic section of the error message
strMsgBoxContent = "An error has occurred during processing within the Sheet Access Add-In:" _
& vbNewLine & vbNewLine & _
strMsgBoxContent _
& vbNewLine & vbNewLine & _
"Please address this issue and try again." _
& vbNewLine & vbNewLine & _
"This process will now terminate"
MsgBox strMsgBoxContent, vbCritical, "File Path Exception"
Call A_TerminateProcess(blnCurrentEvents, blnCurrentUpdating)
End Sub
'If the calling routine has requested Write Permission
'but the opened sheet is in Read Only Mode then the process will be sent here
Private Sub A_WritePermissionError(ByRef wbTargetWorkbook As Workbook, _
ByRef strFullPath As String, _
ByRef blnCurrentEvents As Boolean, ByRef blnCurrentUpdating As Boolean)
wbTargetWorkbook.Close
MsgBox "An error has occurred during processing within the Sheet Access Add-In:" _
& vbNewLine & vbNewLine & _
"You have requested Write Permission from:" _
& vbNewLine & vbNewLine & _
strFullPath _
& vbNewLine & vbNewLine & _
"Only Read Permission is currently available. Please check that nobody else" & _
"is currently locked to the file and that the file properties are not set " & _
"to read only." _
& vbNewLine & vbNewLine & _
"This process will now terminate.", _
vbCritical, "Unhandled Exception Error"
Call A_TerminateProcess(blnCurrentEvents, blnCurrentUpdating)
End Sub
'Generic error handler
'If there is no valid reason for a function to fail it will be passed here
'to confirm the function that failed for further investigation
Private Sub A_UnhandledError(ByRef strErrorLocation As String, _
ByRef blnCurrentEvents As Boolean, ByRef blnCurrentUpdating As Boolean)
MsgBox "An SheetAccess_AddIn Error has occured while processing the following function:" _
& vbNewLine & vbNewLine & _
strErrorLocation _
& vbNewLine & vbNewLine & _
"Please contact a member of the VBA Working Group to investigate further." _
& vbNewLine & vbNewLine & _
"Ensure you supply full details of the inputs and process that has failed." _
& vbNewLine & vbNewLine & _
"This process will now terminate.", _
vbCritical, "Unhandled Exception Error"
Call A_TerminateProcess(blnCurrentEvents, blnCurrentUpdating)
End Sub
'Opens the supplied file path, disables/enables events based on instructions
'And sets the Target Workbook object
Private Sub A_OpenFile(ByRef wbTargetWorkbook As Workbook, _
ByRef blnSuppressEvents As Boolean, _
ByRef blnUpdateLinks As Boolean, _
ByRef blnReadOnly As Boolean, _
ByRef strPassword As String, _
ByRef strWriteResPassword As String, _
ByRef strFilePath As String)
If blnSuppressEvents = True And Application.EnableEvents = True Then Application.EnableEvents = False
If blnSuppressEvents = False And Application.EnableEvents = False Then Application.EnableEvents = True
Workbooks.Open Filename:=strFilePath, _
ReadOnly:=blnReadOnly, _
UpdateLinks:=blnUpdateLinks, _
Password:=strPassword, _
WriteResPassword:=strWriteResPassword, _
IgnoreReadOnlyRecommended:=True
Set wbTargetWorkbook = ActiveWorkbook
End Sub
'Controls the Write Access Permission Checks
'Independent from the main control due to the call happening from two places
Private Sub A_WriteAccessChecks(ByRef blnWriteAccessRequired As Boolean, _
ByRef wbTargetWorkbook As Workbook, _
ByRef strFullPath As String, _
ByRef blnCurrentEvents As Boolean, ByRef blnCurrentUpdating As Boolean)
'If write access is required it will check for this
If blnWriteAccessRequired = True Then
If B_WorkbookReadOnlyCheck(wbTargetWorkbook) = True Then Call A_WritePermissionError(wbTargetWorkbook, strFullPath, blnCurrentEvents, blnCurrentUpdating)
End If
End Sub
'Returns ScreenUpdating and EnableEvents back to their starting value before terminating the process before completion
Private Sub A_TerminateProcess(ByRef blnCurrentEvents As Boolean, ByRef blnCurrentUpdating As Boolean)
Application.ScreenUpdating = blnCurrentUpdating
Application.EnableEvents = blnCurrentEvents
End
End Sub
'Checks supplied file path is valid and returns appropriate message
Function B_ValidFilePathCheck(ByRef strFullFilePath As String) As String
If Len(strFullFilePath) = 0 Then
B_ValidFilePathCheck = "No file path has been supplied"
Exit Function
End If
If Not Dir(strFullFilePath, vbDirectory) = vbNullString Then
B_ValidFilePathCheck = "Path Exists"
Exit Function
Else
B_ValidFilePathCheck = "File path supplied does not exist (check spelling)"
Exit Function
End If
End Function
'Checks if the workbook is already open in the application window
Private Function B_CheckForOpenWorkbook(ByRef strFilePath As String, _
ByRef wbTargetWorkbook As Workbook, _
ByRef blnCurrentEvents As Boolean, ByRef blnCurrentUpdating As Boolean) As Boolean
On Error GoTo ErrHandler
Dim wbTemp As Workbook
Dim blnWorkbookOpen As Boolean: blnWorkbookOpen = False
'Checks all open Workbooks for a matching File Path
For Each wbTemp In Application.Workbooks
If wbTemp.FullName = strFilePath Then
blnWorkbookOpen = True
Set wbTargetWorkbook = wbTemp
GoTo ExitHandler
End If
Next wbTemp
ExitHandler:
'Passes the Temp Result back to the Function
B_CheckForOpenWorkbook = blnWorkbookOpen
Exit Function
ErrHandler:
'No obvious reason for valid failures
'Any errors will be sent to the UnhandledError Sub and the
'Process Terminated
Call A_UnhandledError("Z_CheckForOpenWorkbook", blnCurrentEvents, blnCurrentUpdating)
End Function
'Passes back whether the workbook is read only
Private Function B_WorkbookReadOnlyCheck(ByRef wbTargetWorkbook As Workbook)
B_WorkbookReadOnlyCheck = wbTargetWorkbook.ReadOnly
End Function
Display More
So instead of the line:
Application.Workbooks.Open "\\ZXG-FXVR-01\Compliance_NCC$\zXML_Validation\PEP_DOCUMENTATION\DataBase.xlsb", UpdateLinks:=0
In your code, you would replace it with:
call A_ExternalWorkbookAccess(strFullPath:="\\ZXG-FXVR-01\Compliance_NCC$\zXML_Validation\PEP_DOCUMENTATION\DataBase.xlsb", _
blnWriteAccessRequired:= TRUE, blnReadOnly:=FALSE)
Alternatively you can make the workbook shared, not sure what issues that may cause with users overwriting each other's data though.
Re: Late Binding an Object based on its Type after being set
I had a number of other classes which all contain the same properties/methods but what actually went on in them was slightly different.
So I wanted to go with late binding on the code outside the classes so it was object agnostic.
Hopefully that makes sense.
Got the whole thing working now though which means we now have a testing tool that in theory can test any series of calculations in the cobol systems without having to build a bespoke spreadsheet each time, just need to alter the queue of generic calculations to match the larger equations and the appropriate order of operations.
I may be putting myself out a job, not sure I want to give it to management now.
Re: Deleting Groups of Like Rows where a no negative value exists in a specific colum
This should do it:
'Loops through a defined range and deletes entire row where a value > 0 is found in column 3
Public Sub DeletePositiveRows()
Dim wsTemp As Worksheet: Set wsTemp = ThisWorkbook.Sheets("OutputSummary")
Dim lngItemCol As Long: lngItemCol = 2
Dim lngValueCol As Long: lngValueCol = 3
Dim lngStartRow As Long: lngStartRow = 2
Dim lngEndRow As Long: lngEndRow = GetLastRow(wsTemp, lngItemCol) 'Bases the end row on the contents of Column B (2)
Dim lngWrkRow As Long
With wsTemp
lngWrkRow = lngStartRow
Do
If .Cells(lngWrkRow, lngValueCol) >= 0 Then
.Rows(lngWrkRow).EntireRow.Delete
'Deleting the row shifts eveything up so the end row needs adjusted
'Also don't need to advance the row as the lower rows have already been brought up
lngEndRow = lngEndRow - 1
Else
'Only advance the row when a row hasn't been deleted
lngWrkRow = lngWrkRow + 1
End If
Loop Until lngWrkRow = lngEndRow
End With
End Sub
'Gets the last populated row to set the limits of the loop
Private Function GetLastRow(ByRef wsTemp As Worksheet, ByRef lngColumn As Long) As Long
With wsTemp
GetLastRow = .Cells(.Rows.Count, lngColumn).End(xlUp).Row
End With
End Function
Display More
You didn't explicitly say how you want to handle zeros (since these are strictly speaking not negative or positive), in the above code they are handled as positive values and deleted, however if you want to treat them as negatives just remove the "=" from the condition.
Re: Late Binding an Object based on its Type after being set
D'oh!!!!!
I'm a total idiot.
Right after posting that I noticed I was setting clsGenericSum as the objInputStep, it should have been the objCalculationClass and this works exactly as expected now.
Apologies, feel free to close this one down.
Don't know if this is possible but here goes.
But essentially what I'm trying to do is create an application for my area which allows them to queue up various different calculation components to make a larger calculation for testing various systems.
So I've got a master class that handles the ordering of various other calculation specific classes.
The user can input the component calculations in an input sheet and this is then picked up by the code and used to create the appropriate calculation classes in order and add these to a collection in the master calculation queue class.
Since I'm working in the earlier routines with a generic idea of the classes then I've opted for late binding as the object could be one of many classes, they all share some common routines so this is fine at the earlier stages.
However, when I get into specific routines for those classes I use a select case based on the TypeName(LateBoundObject) to dictate which call should be made.
On making the appropriate call the object is passed to a specific routine for that type of object.
At this point I was wondering if it's possible to dictate that object type as it's appropriate class, rather than continuing to reference it as an object.
I don't think set objCalcClass = CreateObject(GenericSum) works as this creates a new version of the object, it's already been set at an earlier stage due to it's order in the collection.
Example of a section of the code:
Private Sub IdentifyObject(ByRef objInputStep As Object, ByRef objCalculationClass As Object)
Select Case TypeName(objCalculationClass)
Case "GenericSum"
Call GenericSumPassValues(objInputStep, objCalculationClass)
Call GenericSumPerformCalculation(objCalculationClass)
Case Else
Stop 'Error Catching Statement
End Select
End Sub
Private Sub GenericSumPassValues(ByRef objInputStep As Object, ByRef objCalculationClass As Object)
Dim varValues As Variant
Dim dblValueToPass As Double
Dim clsGenericSum As GenericSum
Set clsGenericSum = objInputStep 'This was where I tried just to set the specific class based on the generic object but this doesn't work
For Each varValues In objInputStep
dblValueToPass = GetValueFromVariant(varValues)
Call clsGenericSum.AddToValueCalculation(dblValueToPass)
Next varValues
End Sub
Display More
Re: Run an Excel Macro From Powerpoint
[QUOTE=Keifffer;791089]TheGlovner: Wow, what a really clever idea! I tried that, but trying to add a reference (in PPT VBA Editor, to refer to the Excel workbook) I get an error "Can't add a reference to the specified file". I tried saving the workbook as an addin (xlam), with the same "Can't add a reference to the specified file".
QUOTE]
Yeah, I tried it myself and encountered the same issue. My thinking is because to open an excel workbook (add-in or otherwise) you require an instance of the excel application. When you reference an excel workbook from another excel workbook it will open the "parent" workbook and then open it's references in the same instance of the application.
So when you open a powerpoint file in an instance of the powerpoint application, you could only reference other powerpoint files in the VBA (as this would open them inside that instance of the powerpoint application), it won't let you reference an excel file directly as that file can't be opened in that instance of the powerpoint application (because it's not a powerpoint file, it's an excel file, so it needs to open it in an instance of an excel application).
I hope that makes sense.
To answer your other point though about having to do this on every PC. You wouldn't need to do that as the referencing is part of that file. So when that file is opened on another PC (provided it's by the same link rather than an attachment on an email) the reference still applies.
Doesn't help you here but may be useful for future excel developments.
Re: Calculate button
You're not far off, two ways you could tackle things, I'm more inclined to have a button be used to call a larger section of code rather than embedding the code within the button click event so I'll show you that:
Sub Botón1_Haga_clic_en()
Call Worksheet_Calculate
End Sub
'apply cells colors from single-cell formula dependencies/links
Private Sub Worksheet_Calculate()
Dim Cel As Range
Dim RefCel As Range
On Error Resume Next
For Each Cel In ActiveSheet.UsedRange
If Cel.HasFormula Then
Set RefCel = Evaluate(Mid(Cel.Formula, 2))
Cel.Interior.Color = RefCel.Interior.Color
End If
Next Cel
End Sub
Display More
Your issue was around the fact you were trying to embed the functional subroutine inside the button click event routine, rather than calling it from the button click routine.
Re: Run an Excel Macro From Powerpoint
Never had to do this, but off the top of my head before I find the time to and recreate and solve the problem can you possibly make the excel file a referenced add-in through the powerpoint VBA? Should make communication and rights easier to handle between the two then.
Re: Algorithm / Assign Max Value
Fantastic, glad you got there in the end.
Apologies for the quality of writing in my last post, that was done on my mobile on the bus heading home from work.