Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Remember me

Go Back   Tutorialized ForumsDatabasesMySQL

Add This Thread To:   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 2.00 average. Display Modes
Unread Tutorialized Forums Sponsor:
Old March 11th, 2013, 01:39 AM
anjusaini anjusaini is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
Join Date: Mar 2013
Posts: 1 anjusaini User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 34 sec
Reputation Power: 0
How to do Formatting Using Macros


I need to generate a document wherein corresponding values will be filled as per the database.
o I am using bookmarks for the same ( shown below) . Also I am using macros for the same ( Shown below ) .
The problem I am facing are:

1. Where there is no value for the particular field , my bookmark name is appearing ; whereas it
should be blank.
2. As per the example , I have 2 values for a particular field . and my value is appearing in a single line with @@

My Doc ::

Name : [Name]
Phone(Optional) : [Phone]
Country :[Country]

These are the three fields. I have used the bookmarks. Since my Phone column is empty sometime , it
should show me as a blank but , it is showing the bookmark.

Similary, Country field has two values say : India and America. The value should appear as

Country : India

Whereas my values are coming like India@@America

Please help me

My Macro ::

Public Sub DefaultMacro()
Dim lngCpt As Long
Dim strBookmarkName As String
Dim strBookmarkValue As String

FormatTable "Name", "@@", 1
FormatTable "Phone", "@@", 1
FormatTable "Country", "@@", 1

'Clear unused bookmarks

End Sub

Private Sub RemoveUnusedBookmark()
Dim lngCpt As Long
Dim strBookmarkName As String
Dim strBookmarkValue As String

For lngCpt = 1 To ActiveDocument.Bookmarks.Count
strBookmarkName = ActiveDocument.Bookmarks(lngCpt).Name
Selection.GoTo What:=wdGoToBookmark, Name:=strBookmarkName
strBookmarkValue = Selection.Text
If strBookmarkName = strBookmarkValue Then SetBookMark strBookmarkName, ""
Next lngCpt

End Sub

Public Sub SetBookMark(ByVal pstrBookmark As String, ByVal pstrValue As String, Optional ByRef pwrdActiveDocument As Document, Optional ByVal pblnKeepBookmark As Boolean = True)
Dim wrdRange As Range

On Error GoTo ActivateError
If pwrdActiveDocument Is Nothing Then
Set pwrdActiveDocument = ActiveDocument
End If
If Not pwrdActiveDocument.Bookmarks.Exists(pstrBookmark) Then Exit Sub
Set wrdRange = pwrdActiveDocument.Bookmarks(pstrBookmark).Range
wrdRange.Text = pstrValue
If pblnKeepBookmark Then wrdRange.Bookmarks.Add pstrBookmark
On Error GoTo 0
End Sub

Private Sub FormatTable(ByVal pstrBookmark As String, ByVal pstrSeparator As String, ByVal pintNbrCol As Integer)
Dim strTemp As String
Dim strTemp2 As String
Dim intCpt As Integer

Selection.GoTo What:=wdGoToBookmark, Name:=pstrBookmark
strTemp = Selection.Text

If InStr(strTemp, pstrSeparator) = 0 Then Exit Sub
While InStr(strTemp, pstrSeparator) > 0
strTemp2 = Extraire_(strTemp, pstrSeparator)
Selection.Text = strTemp2
For intCpt = 1 To pintNbrCol
Selection.MoveRight Unit:=wdCell
Next intCpt
If Len(strTemp) > 0 Then Selection.Text = strTemp
End Sub

Private Function Extraire_(ByRef value As String, Optional ByVal Separator As String = ",") As String
If InStr(value, Separator) = 0 Then
Extraire_ = value
value = ""
Extraire_ = Mid$(value, 1, InStr(value, Separator) - 1)
value = Mid$(value, InStr(value, Separator) + Len(Separator))
End If
End Function

Reply With Quote

Viewing: Tutorialized ForumsDatabasesMySQL > How to do Formatting Using Macros

Developer Shed Advertisers and Affiliates

Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap