I'm trying to read and write a list of properties from files (mainly doc and xls), like Title, Author, Tags or Comments. I can easily get basic attributes, but not these extended ones.
GetDetailsOf used to work ( https://technet.microsoft.com/en-us/library/ee176615.aspx?f=255&MSPPError=-2147217396 ) however now it stops dead at index 6.
According to the Docs ( https://learn.microsoft.com/en-us/windows/desktop/shell/shellfolderitem-extendedproperty ) .ExtendedProperty is supposed to be able to read attributes, but it doesn't return most of them. For example Author(s), which is even cited as an example in the link above (There are two ways to specify a property. The first is to assign the property's well-known name, such as "Author"), returns nothing.
Is there another way?
Test script for a single file:
Sub PrintDocumentProperties()
With CreateObject("Shell.Application").Namespace("D:\VBA")
MsgBox .GetDetailsOf(.Items.Item("derp.xlsm"), 5) & vbNewLine & _
.Items.Item("derp.xlsm").ExtendedProperty("Date modified") & vbNewLine & _
.Items.Item("derp.xlsm").ExtendedProperty("Type") & vbNewLine & _
.Items.Item("derp.xlsm").ExtendedProperty("Size") & vbNewLine & _
.Items.Item("derp.xlsm").ExtendedProperty("Author") & vbNewLine & _
.Items.Item("derp.xlsm").ExtendedProperty("Authors")
End With
End Sub
Related
I'm using PowerPivot, and I'm creating a table in the datamodel using the next code:
Set ObjConn = ActiveWorkbook.Connections.Add2( _
Name:= "SomeConnName", _
Description:="DescSomeConn", _
ConnectionString:="OLEDB;Provider=OraOLEDB.Oracle;Data Source=XXXX;User ID=YYYY;Password=ZZZ;Persist Security Info=true", _
CommandText:="SELECT * FROM mytable", _
lCmdtype:=xlCmdSql, _
CreateModelConnection:=True, _
ImportRelationships:=False)
It works well, except it always create the table named "Query".
I already searched in Microsoft Documentation and googled this way too much and I can't directly find where or how to set the table/query name.... or how to rename it after it was created.
Help is appreciated.
EDIT
Thanks to #QHarr guide, I changed my approach to this:
ActiveWorkbook.Queries.Add Name:="QueryXY09", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = OleDb.DataSource(""provider=OraOLEDB.Oracle.1;data source=MyDWHConn;"", [Query=""SELECT * FROM mytable""])" _
& Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Source"
ActiveWorkbook.Connections.Add2 _
"Query - QueryXY09", "Connection to the 'QueryXY09' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=QueryXY09;Extended Properties=", _
"""QueryXY09""", 6, True, False
Which makes the goal, now I can set the name of the connection.
But this represents two problems. First data extraction is clearly slower, it seems it is using .net libraries, also, it looks like a double step.
Second, now I don't have a place to store the password, neither connection accept the user id/password for this approach. This last is the most worrisome, since the purpose of this is, of course, the automation of the extraction of data. However, I notice that, when I moved the file to a testing server, it prompted me for the user/password once, then I closed everything, open again and there was no prompt. So, where was the password saved?
I am playing with a script that sends emails from an excel sheet. the body of my email is not compiling. However I have wrapped everything in "" with & _ breaks for when it goes too far and .value _ & vbNewLine & _ for line breaks
I have tried annotating out chunks of the email body to fish out the syntax error
.Body = "Hello " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"this is Paul from the XYZ and I just left you a voicemail message for you. " & _
"We are reaching out to you because you’ve been identified in the XYZ system as someone who manages XYZ " & _
"The XYZ form, which you have been using, will be retired after XYZ and be replaced with a new process and system. " & _
"If you onboard XYZ for your organization, this means you will be directly impacted. " & _
"We need to collect your information to set you up in our new system and ensure there is no interruption moving forwards. " & _
"We will reach out again and if you can please provide the following information below: ".Value _
& vbNewLine & vbNewLine & _
"Best email to contact you: ".Value _
& vbNewLine & _
"Best phone number to reach you: ".Value _
& vbNewLine & _
"Best time of day to schedule our next call: ".Value _
& vbNewLine & vbNewLine & _
"If you have any questions or concerns, please don’t hesitate to reach out directly to me at XYZ ".Value _
& vbNewLine & vbNewLine & _
"Thank you, "
Email should go out. But instead I get a syntax error compile error
"Best email to contact you: ".Value _
There's the error. That .Value member call is illegal, a string literal doesn't have members. You probably mean to be doing this:
"Best email to contact you: " & .Value _
Same here:
"Best phone number to reach you: ".Value _
And here:
"Best time of day to schedule our next call: ".Value _
And here too:
"We will reach out again and if you can please provide the following information below: ".Value _
Now, the inconsistency of whether you put the & at the end or at the start of a line, makes the code extremely hard to parse. Decide whether you want it at the end or at the beginning, and stick to it.
I have a function (bastardised from Ron DeBruin's Website) that saves the active or selected sheet as a pdf and sends it as an attachment in outlook. It still works for everyone I've given it to but lately, it is not working on my PC. I keep getting the error message as if VBA cannot save the file (due to the path being invalid or the name being used already and not wanting to overwrite)
Running on various PCs that are either running on Windows 10 or 7 (I'm on Win10) I've tried changing the save file path & the filename in the code to something more simple and I still have the same issues. I tried the file on another machine running windows 10 and had no issues. I've also tried checking Microsoft Add-Ins and everything is fine.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub RDB_Worksheet_Or_Worksheets_To_PDF_And_Create_Mail()
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more than one sheet selected," & vbNewLine & _
"be aware that every selected sheet will be published"
End If
'Call the function with the correct arguments
'Tip: You can also use Sheets("YourSheetName") instead of ActiveSheet in the code(sheet does not have to be active then)
FileName = RDB_Create_PDF(Source:=ActiveSheet, _
FixedFilePathName:="C:\Users\" & Environ("Username") & "\Documents\Container Shipment Reports\" & (Range("G4").Value) & ".pdf", _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'For a fixed file name use this in the FixedFilePathName argument
'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:="XXXXXX.XXXXXXX#XXXXX.com.au", _
StrCC:="XXXXXX.XXXXXXX#XXXXX.com.au; XXXXXX.XXXXXXX#XXXXX.com.au", _
StrBCC:="", _
StrSubject:="Container Shipment Report " & (Range("G4").Value) & ".", _
Signature:=True, _
Send:=False, _
StrBody:="<body>Hello,</body><br>" & _
"<body>Please see the attached Container Shipment Report# " & (Range("G4").Value) & " from " & (Range("E4").Value) & "." & _
"<br><br>" & "Thank you.</body>"
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exists"
End If
Application.Quit
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
This should convert to PDF, attach to an email, send the email and then close Excel. At the moment I am just getting the MsgBox response from the code, "Not possible to create PDF, possible reasons: etc".
(there is also a function to stop the excel file saving as it is meant to be a blank template.) As I said this seems to be an issue only on my machine but as it works on other computers I'm thinking there's no issue with the code.
I have an issue, have an AutoCAD file with a ton of data links and would like to update only the data links related to a speciffic table.
Simmilar to the functionality of selecting a table with data links, right clicking and selecting Update Table Data Links.
i have the following code:
Private Sub Update_table_data_link(tblRef As AcadTable)
ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "K" & vbCr
End Sub
It works but updates all the data links in the drawing (which is a problem) so a perfect solution would either let me get what links are associated to tblRef
and change the line to:
ThisDrawing.SendCommand "DATALINKUPDATE" & vbCr & "U" & vbCr & "D" & vbCr & "datalink_name_from_tblRef" & vbCr
or directly send the command to update the links to tblRef
After much digging around and a lot of help, here is the answer:
Private Sub Update_table_data_link(tblRef As AcadTable)
ThisDrawing.SendCommand "DATALINKUPDATE " & vbCr & "U" & vbCr & Ent2lspEnt(tblRef) & vbCr & vbCr
End Sub
Public Function Ent2lspEnt(entObj As AcadEntity) As String
'Designed to work with SendCommand, which can't pass objects.
'This gets an objects handle and converts it to a string
'of lisp commands that returns an entity name when run in SendCommand.
Dim entHandle As String
entHandle = entObj.Handle
Ent2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
End Function
note that "Update_table_data_link" has a table as input
I have a function which sets a variable for the current user. The variable name is prefixed with the name of the module - basically, the way the application is set up, Client is a class, Server is a class, Agency is a class and so on. This is an attempt to create a system whereby we can find out any key information about a client or one of their websites, across over 200 servers, with as few clicks as possible and using live data from their DB.
The function is as follows:
public sub setVariable(varName, varValue)
varValue = cstr(varValue)
def = ""
if varValue = "" then def = "1"
response.write vbcrlf & "Variable: " & varName & " : " & varValue & vbcrlf
if not cstr("" & getVariable(varName, def)) = cstr("" & varValue) then
response.write vbcrlf & varName & " : " & varValue & vbcrlf
prepend varName, "Module." & Name & "."
response.write vbcrlf & varName & " : " & varValue & vbcrlf
session(varName) = varValue
Core.RunSproc "SetUserVariable", array("#name", "#value"), array(varName, cstr(varValue)), setVar
end if
end sub
Now on line 5, where it is first output, only "ID" is output as the variable name. However 2 lines later the name is set to "Module.<module-name>.ID" (for example Module.Server.ID. 2 lines after that, after the prepend statement (which acts the same as doing varName = "something" & varName), it outputs the something + "Module.<module-name>.ID". In effect, in this case, it outputs "Module.Server.Module.Server.ID". Note that if I take anything out, it is taken out of the first Module.Server but not the 2nd. Does anyone have any idea what is causing this? It seems as though Module.Server is being prepended to the variable name between lines 5 & 7, but the only line there is an if statement. Thanks in advance.
Seems I have found the answer. It's the fact that ASP automatically assumes variables input into functions are byref. Thus, when calling getVariable, I was actually prepending "Module.Server." there too, and because it was byref the variable maintained the value.
Regards,
Clarkey