Compile error can't find project or library - excel

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.

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?

VBA script issue specifying command line

So I'm fairly new to VBA, using it within some spreadsheets so forgive me if this is a super obvious fix, I'm sure it is but have spent hours on with with no success.
The following piece of code will lie inside of an if statement - not sure if thats worth mentioning or not.
I want to simply move, and rename files from one location to the other
It needs to utilize cmd.exe, and use the 'move' argument - the source path and source destinations will be changeable depending on the pc - so it will need to use the '%temp% - as the initial file will be stored in this folder, and %userprofile% for the destination path.
Here is the code so far - I think the issue is just to do with the formatting -
Sub movefile ()
Dim Origpath As String
Dim NewPath As String
OrigPath="%temp%\newfile.txt"
NewPath="%userprofile%`Documents\newfile.vbs"
<<next code inside of an if statement>>
moveFile="C:\windows\system32\cmd.exe /C move " & OrigPath & " " & NewPath
End Sub
Maybe the " and & arent placed correctly? But the code works fine up until the line 'movefile...'
Probably a super easy way of doing it - help please!!
Try using Name:
name OrigPath as NewPath
Alternatively you can use use fdo movefile, as explained in this answer.

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.

Language independent way to get "My Documents" folder in VBA Excel 2003

I need a Language independent way to get "My Documents" folder in VBA Excel 2003.
What I have:
Public Function MyDocsPath() As String
MyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
End Function
Because the program will be used in at least 2 lang MS Windows, and the "My Documents" name changes for each language.
Is there a way, or should I try to figure out the system lang and become specific?
This may suit:
Set WshShell = CreateObject("WScript.Shell")
strDocuments = WshShell.SpecialFolders("MyDocuments")
From: http://msdn.microsoft.com/en-us/library/0ea7b5xe.aspx
Although the special folder name is MyDocuments, it refers to the documents folder for several versions of Windows.
You may use "Documents", as the localized versions point to the same location.
' Application.PathSeparator can be used, but this
' is unlikely to work on non-Windows environments
MyDocsPath = Environ$("USERPROFILE") & "\Documents\"
(Seeing that this is a 10 years old question it may not have been the case back then. :)

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