Words's fullname property with OneDrive - vba

I would like to do the same as this which was written for Excel, but in Word
Excel's fullname property with OneDrive
I get Object issues using Philip Swannell's method. Much appreciated.

Related

MS Access Table (and TableDef) Properties

A table in MS Access opened in Design View exposes several properties, as does the table's Property Sheet. Many of these properties are undocumented or documented only for other objects. The question is, to which object do these properties belong? Further, how does one identify them in code? Pressing F1 for context help in each case reveals no clues.
Examples include (and recognize that the names below follow from their visual context, not an object model):
Field.Description is a column in Design View (along with Field Name and Data Type) but is undocumented. Also, iterating DAO.Field.Properties reveals no Description field and references to the property fail.
Table.Description appears in the Property Sheet but also is undocumented.
Table.Filter and Table.OrderBy and their ~OnLoad counterparts appear on the Property Sheet but are documented only for other objects. I understand that information specified here is intended somehow to flow through to forms for which the table is the RecordSource, but the mechanism is not obvious and still leaves the initial question, flowing through from which object's property.
Table.LinkChildFields and Table.LinkMasterFields appear in the Property Sheet but are documented only for other objects. Also, their use in this context is not obvious.
Other table properties on the Property Sheet tell the same tale.
Any thoughts, in general or specific to any of the foregoing, would be most helpful and appreciated.
To show properties of some Access database object (table, query, form, report, ...), we can do this on VBA, defining this global function:
Function objShowProperties(ByVal xobj As Object)
Dim i As Long, varPropValue, prop As Object
On Error Resume Next
'
' loop over properties:
'
i = 0
For Each prop In xobj.Properties
varPropValue = prop.Value
'
' sometimes we have error accessing property value:
'
If (Err <> 0) Then
varPropValue = "[UNAVAILABLE]"
Err.Clear
End If
Debug.Print prop.Name, "=", varPropValue
i = i + 1
Next
On Error GoTo 0
Set prop = Nothing
objShowProperties = i
End Function
In my Acccess db I've a table named customers.
To show properties of this table, I call the above function like this:
objShowProperties CurrentDb.TableDefs("customers")
In my debug console, I got this:
All listed properties can then be accessed directly on VBA code, eg, RecordCount property:
dim lngRecords as long
lngRecords = CurrentDb.TableDefs("customers").Properties("RecordCount")
Hope this will help you.
A few things:
Field.Description is a column in Design View (along with Field Name and Data Type) but is undocumented.
No, it is not un-documented.
You are confusing DAO, and that of ms-access.
DAO "field" does not have a description property. So, it not un-documented at all.
Also in Access, there is help. You an put your cursor in the description, and hit help, and you get this:
so, place cursor here, and hit f1 for help:
And now you get this:
So, you are confusing the database engine object called DAO.FIELD with that of ms-access and it allowing you to have/enjoy/see a description in the table desinger.
I should point out that the DAO object model does not have a table designer!!!
In fact, what Access does is add's a custom property to the field, and then display's that. So, field.Description is not un-document, it in fact does not exist.
As noted in the other post here, you can "interate" all of the properties. However, if you use the database engine outside of ms-access, and EVEN create fields in code (or even by sql commands), you WILL STILL find that no descripton property exists. However, as noted, there is this thing called help, and you can give help a try, as it will explain what the description setting in ms-access does.
However, at the end of the day, field.description is not un-documented, and in fact does not exist.
so, if you read/look at/see documentaiton for the DAO field object, then these properties and options will not be found.
After all, you might be using c++, c# or some other system and that database engine that MS-Access just also happens to use.
MS-Access is not the database here. It is a tool that lets you build software, and forms and reports, and write code.
When you using MS-Access, you are not required to use the JET (now called ACE) database engine to store your data. You are free to use the Oracle database, or SQL server or whatever.
So, features of Access and things like link master fields etc.?
Those are MS-Access features, and not the database engine (ACE) features.

Calling Excel's worksheet function from vba code

With worksheetfunction's methods I can call from vba code a lot of excel's function without reinvent the wheel.
Unfortunately not all function are available there but other simple function can be find under vba library.
Now I need to use two functions:
address()
indirect()
But none of two is available as method of vba or worksheetfunction
(here what is available: https://msdn.microsoft.com/en-us/library/office/ff822194(v=office.14).aspx)
Using the object browser on the editor I can't find those functions...
how can I do?
INDIRECT is a way of resolving a string, this can be done in VBA easily. ADDRESS can also be found as a member of a Range object. That's why they are not available.
Here is a tiny example:A1 contains the text B1B1 contains the text GoldC1 contains the formula:=INDIRECT(A1):
Running this macro:
Sub UsingEvaluate()
MsgBox Evaluate("INDIRECT(A1)")
End Sub
will produce:

Does vba in word and excel uses different declaration?

I am trying to use this json converter https://github.com/VBA-tools/VBA-JSON in microsoft word.
It works excelent in excel with ms-scripting runtime.
however it fails in microsoft word.
the problem I think is object type declaration.
In microsoft word this line gives error.
Set json_ParseObject = New Dictionary
after reading https://msdn.microsoft.com/en-us/library/office/gg251782.aspx
I tried converting it to
dim json_ParseObject As Dictionary.
It give error of duplicative declaration so i removed it.
it then gave error at:
Set json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)
Does anybody have ever used this project for word-vba successfully?
I earlier asked this question while I was not aware of problem. after some research I am asking it again. Please try to understand the problem as it is real. Please guide if you thing this question is off-topic
In microsoft word this line gives error.
This is because in Word there already exists a class Dictionary but this Word class can't be created with New. So it is a collision of Scripting Runtime Dictionary and Word Dictionary.
In Word fully qualify the name of the Dictionaty type with the name of the library:
Dim d As Scripting.Dictionary
Set d = New Scripting.Dictionary

VBA properties type

I know this is ultra basic in VBA but i have searched on 6 books (VBA for dummies 2010, Excel Bible, Proffesional Excel Development: The deffinitive guide, VBA and Macros Excel Microsoft 2010, Excel programming with VBA, Microsoft Excel VBA Proffesional Projects) and noone gives a deffinition about the 3 types of properties read-only, write-only and read/write.
They probably think is way to basic to even mention in their books but hey if you believed as i that computers were electricity purification filters 11 months ago and know you wanna code now someone has to tell ya a clean cut explanation
thanks for watching my question
As the names suggest
Read Only Property is a property from which you can read but not write to it. For example, For a range .Text is a Read Only Property
Msgbox Range("A1").Text
If you try to write to it, for example
ActiveSheet.Range("A1").Text = "Blah Blah"
then you will get the message showing an error Runtime Error 1004 - Unable to set the Text property of the Range Class
Write-only Property are moderately rare. Write Properties are simply properties that have Property Let or Set method but no Get Method.
Private MyName As String
Property Let sName(Value As String)
MyName = Value
End Property
Read/Write Property is pretty self explanatory. You can read and write to it. For example, for a Range .Value is a Read/Write Property
Range("A1").Value = "Blah Blah"
Extra Note: Courtesy #Mehow
When you press F2 in the Visual Basic Editor, the Object Browser pops up. If you click on any of the classes and then members of that class you can see in the left bottom corner which properties are read/write.

Font of all headings in a Word Document

I am trying to retrieve the font name and size of all the headings from a word document. Any idea how to get it?
The basic structure will be something like below:
Public Sub ShowFontAndSize()
Dim singleLine As Paragraph
Dim lineText As String
For Each singleLine In ActiveDocument.Paragraphs
Debug.Print singleLine.Range.Font.Name
Debug.Print singleLine.Range.Font.Size
Next singleLine
End Sub
The catch will be that this won't sense if there are different fonts and sizes on the same line. If that's a possibility, you will need to add another loop with For Each singleCharacter In singleLine.Range.Characters inside of the paragraphs loop.
Edit: A trickier problem is what to do with this data once you've collected it. Building up an array seems like the natural fit, but VBA arrays are borderline useless, since basic methods like .append() require you to redim the whole array. See http://www.cpearson.com/excel/VBAArrays.htm for more info if you would like to go down that road.
The most straight forward solution is to open the document in Word and access the object model. This is traditionally done using VBA, but you can also use .NET (e.g. C# og VB.NET) by using VSTO (Visual Studio Tools for Office). Personally I find C#/VB.NET much better languages than VBA.
Once you have access to the object model you will have to enumerate paragraphs in the document. When you find a heading (perhaps defined by the style) you will have to figure out the formatting of the heading.
This is what I got from a brief skim of the MSDN page on "HeadingStyles":
MsgBox ActiveDocument.HeadingStyles(1).Style