VBA - "FORMAT" function isn't recongnised on 1 computer - excel

I've coded something in VBA to help my co-workers and it's working on 8 computers but on this one computer, everytime I try to start the code, it gives me an error.
Sorry I'm translating from French into English but the error is:
Compilation error:
Project or library isn't found
The actual code is:
' ============================================
' === TRAITEMENT DES PRODUITS DU GROUPE 10 ===
' ========== FOURNISSEURS STANDARDS ==========
' ============================================
Case 10
Select Case var_Prix
Case Is < 25
Range(COLLISTE & var_Ligne).Value = Format(99999, "#,####0.0000")
Range(COLPRIX2 & var_Ligne).Value = Format(var_Prix / (0.5 - TRANSPORT), "#,####0.0000")
Range(COLPRIX3 & var_Ligne).Value = Format(var_Prix / (0.52 - TRANSPORT), "#,####0.0000")
Range(COLPRIX4 & var_Ligne).Value = Format(var_Prix / (0.55 - TRANSPORT), "#,####0.0000")
Range(COLPRIX5 & var_Ligne).Value = Format(var_Prix / (0.6 - TRANSPORT), "#,####0.0000")
<the code continues>
and it has Format highlighted. Seems like the "Format library" isn't installed but I've tried Google and apparently "Format" is installed with windows or office.

As JKP asked, are there any references marked as "missing"? A missing Ref can cause unpredictable behaviour in other referenced libraries.
As a temporary solution, try forcing the reference by putting VBA. before the format, like
= VBA.Format(99999, "#,####0.0000")
This normally works.

Had this issue recently. Cause was 'something' had disabled the "Analysis Toolpack - VBA" Add-in.

so just had this issue. The solution we found was to add Microsoft Scripting Runtime and Microsoft Word 16.0 Object Library back to the References - VBA Project selection.
Not sure which one actually fixed it. But both made the rest of my file work.

Related

Invalid name for Parameter for FullSeriesCollection

I've been using curves names that have a "Δ" as the first character [CharW(916)] in the name, this has not caused any problem until recently. The code snippet below worked fine in the past, but for the "last few months" -- can't be more definite -- this has caused Excel to crash inelegantly without error/warning. Currently running Microsoft 365 Version 2205 (Build 15225.20204 Click to Run)
vw = ChrW(916) & "Cases." & vc(1, i) ' e.g., The curve name (vw) is "ΔCases.W10"
ActiveChart.FullSeriesCollection(vw).IsFiltered = True ' Excel now barfs on this line...
I'be changed the "Δ" character to "d" as an obvious work-around, but that's not really the point... Any observations?

ProjectFile.getDefaultCalendar is mismatch with ProjectProperties.getDefaultCalendarName

I am using MPXJ 7.8.1 to read MS Project File(.mpp). I changed the Project Calendar to "24 Hours" as following:
ProjectProperties.getDefaultCalendarName returns the correct calendar name "24 Hours".
But the ProjectFile.getDefaultCalendar returns the incorrect calendar "Standard".
...
UniversalProjectReader reader = new UniversalProjectReader()
ProjectFile projectFile = reader.read(stream)
ProjectProperties projectProperties = projectFile.getProjectProperties()
"projectProperties.getDefaultCalendarName = " + projectProperties.getDefaultCalendarName() + ", projectFile.getDefaultCalendar = " + projectFile.getDefaultCalendar().getName()
Output: projectProperties.getDefaultCalendarName = 24 Hours, projectFile.getDefaultCalendar = Standard
Is there a way to get the correct calendar?
I've tried this locally with MPXJ 7.9.1 and the functionality seems to work as expected. If you are still having issues, can you open an issue on GitHub and attach an MPP file which demonstrates the problem - thanks!
I recently dug it more and found out that this is caused by the software "Project Plan 365" I use. In the file generated by it, the value of the default calendar is incorrect, which makes it unrecognizable when read with MPXJ. Files generated using MS Project do not have this problem.

Compile error can't find project or library

I'm not familiar with VB6 , I would like to compile an existing project in a new environment (which mean new desktop) , so do I missed some development tools or references to run the code below ? Because when I running the project it pointed to (Date) .
ExcelSheet.Cells(2, 1).Value = "Printed As At " & ls_now
If optCurrent.Value = True Then
ExcelSheet.Cells(4, 1).Value = "Year : " & Year(Date)
Else
ExcelSheet.Cells(4, 1).Value = "Year : " & cboYear.Text
End If
Please Help , thousand thanks
This is usually a side effect of a missing project reference. Hit the Project->References menu:
Look for anything that is marked as 'MISSING'. Those are the things that need to be installed/registered on your development machine. Once you do so, you'll have to restart VB to reload your project.
If Date is VB6's Date function it needs () after it. In all basics except VB.NET, functions must have brackets, and subs musn't. There is also a Date statement that sets the date. That what yours is being interpreted as, but it makes no sense inside another functions parameters.
You could have pressed F1 and learnt this.

Mac 2011 using some functions in VBA

I have recently transferred a working set of routines from Windows Excel 2003 and tried to run them in Excel for Mac 2011. It fails on the first attempt to use the left function. With the error message "cannot find project or library". I have tried setting up a test function to run various text functions and things like Len work but neither left right or mid. The routine is the start of a process to handle exported Access data. Do not think that is relevant as the routine does not start because of the problem with left.
This is my test code.
Function testfunctions()
Dim carrier, carrier2
carrier = "Alpha1"
carrier2 = Left(carrier, Len(carrier) - 4)
MsgBox carrier
End Function
Any suggestions greatly appreciated!
What happens if you remove an errant space in this line (yours)
carrier 2 = Left(carrier, Len(carrier) - 4)
Change to this:
carrier2 = Left(carrier, Len(carrier) - 4)

How do I set up a COM Server interface with Excel?

Versions
Excel 2003Windows XP SimaPro 7.3.0 Developer Version Using a Work computer but was made administrator on this machine Libraries referenced in Excel/VBA: Visual Basic for Applications; Microsoft Excel 11.0 Object Library; OLE Automation; Microsoft Office 11.0 Object Library; Microsoft Forms 2.0 Object Library; COM+ 1.0 Admin Type Library; COM MakeCab 1.0 Type Library; COM+ Services Type Library; SimaPro Library Me: Beginner
What I'm trying to do
I am using a program called SimaPro that stores databases of "Life Cycle Analysis" information. The program has built in COM interface functionality. The program states that it does, indeed support Excel/VBA (but it doesn't specify versions).
I am trying to connect this program and/or COM server to excel so that I can interact with the information through excel.
What I've done
I've done the procedure they list:
-Open SimaPro
-Register COM Server
-Then I pasted the below code into VBA and tried to run it. This code is the sample code provided by the software company, I edited only the SP.Server, SP.Alias, SP.Login, and SP.OpenProject fields (below is as edited).
What Happened
Run-time Error: '-2147418113 (8000ffff)':
Automation Error
Catastrophic Failure
Question(s)
-Is the server name right? I've been reading a little on COM servers and I don't know if the way I put it in is in the right "form"
-Could it have something to do with certain registered/unregistered DLLs? I've worked with the company's IT people, and software programmers. None of them were very familiar with COM but one person suggested the DLLs might be the issue.
Thanks for your help!!
Here is the code that I'm inputting:
Sub CreateProcess()
Dim SP As SimaProServer
Dim PC As Process
Dim PC2 As Process
Dim PL As ProcessLine
Dim Param As ParamLine
Dim Subs As Substance
Set SP = New SimaProServer
SP.Server = "Local Server"
SP.Alias = "C:\Documents and Settings\All Users\Documents\SimaPro\Database\"
SP.Database = "Professional"
SP.OpenDatabase
SP.Login "", ""
SP.OpenProject "PROJECT", ""
' Not project's actual name, not allowed to state name of project
SP.CreateSubstance "Air", Subs
Subs.CASNumber = "4-5-13"
Subs.Name = "Some substance"
Subs.DefaultUnit = "kg"
Subs.Update
SP.CreateProcess ptMaterial, PC
Set PL = PC.AddLine(ppProduct, -1)
PL.ObjectName = "Steel 2"
PL.UnitName = "kg"
PL.Amount = "2"
PL.Comment.Add ("My new created process")
PL.CategoryPath = "Chemicals\inorganic"
PC.Update
' create second material process Case
SP.CreateProcess ptMaterial, PC2
Set PL = PC2.AddLine(ppProducts, 0)
PL.ObjectName = "Case 2"
PL.UnitName = "kg"
PL.Amount = "10"
Set Param = PC2.AddParamLine(ptInputParameter, -1)
Param.Name = "A"
Param.Value = "2,3"
' add input from Steel
Set PL = PC2.AddLine(ppMaterialsFuels, -1)
' input from steel
PL.SetProduct "Introduction to SimaPro 7", ptMaterial, "Steel 2"
PL.Amount = "8"
PL.UnitName = "kg"
Set PL = PC2.AddLine(ppAirborneEmissions, -1)
' input from steel
PL.SetSubstance "Some substance", ""
PL.Amount = "A+1"
PL.UnitName = "kg"
PC2.Update
SP.Logout
SP.CloseDatabase
Set SP = Nothing
End Sub
Given that this was more than one year ago. I'm assuming you got this working. If you haven't yet, I might know what the root cause might be.
I used to get the same error and from your changes for server, alias and login, I was able to make it run. One thing that is different is that you have changed the name of the project to "Project" from "Introduction to SimaPro 7". I honestly have zero (not being humble here) VBA knowledge. So, I'm speculating that there is no project names "Project" to open. I'm not sure if VBA would create a project automatically, if it can't find it. You can either try creating a project named "Project" or just rename it back. I am interested to see if that worked.
Automation Error usually means that there was a problem within the COM library you try to use. As it is a run-time error, it could be something very stupid, as missing parameter or wrong path or access rights. In my opinion, it also means that the library is not very well designed.
As you are not the author of the library you do not have many options. You can try to contact the vendor to get more documentation. You can also pray that the designer thought about logging - check the event log; if you are lucky you may find something interesting there.
Answering your first question, if you referenced the library and the code compiles - that means that you did everything right there.

Resources