I have written a program that generates a report that can be viewed in MS Excel and MS Word. Whereas MS Excel is happy to display a couple of 1000 graphs, MS Word goes mad when pasting in more than 100 graphs.
MS Word also becomes pretty slow when pumping in so many data. Is that a limitation of MS Word or do I have a programming error in my code?
Has anybody of you written a script that outputs a couple of 1000 jpg picture in MS Word?
Code
Sub open_Word()
Dim Exclusion_Limit, Y_distance, NoG, oldj, Number_of_Drugs, max_hits, i, Replicate, j, ii, msg As Integer
Dim Start, graphcount, number_of_hits, teiltabelle, Number_hits_pointer(3), upperlimits(3) As Integer
Dim Zeilen, Var, Var2, X_graph, y_graph, Header_or_Footer, List_y_pos(4) As Integer
Dim found_MS_Wurg, weiter, Show_Graph, date_YON As Boolean
Dim dummy, body_font, headline_font, cmpd_name, disclaimer, error_string As String
Dim Wordobj As Word.Application
Dim WordDoc As Word.Document
Dim kinaselist(4), kinasegroup(3), histogram(3), neue_seite, three_d_plot, rfu_plot, pie_chart, array_graph, word_out As Boolean
word_out = Sheets("3d rotate").Cells(73, 23)
'Teste wieviele graphiken vorhanden sind.
If word_out Then
disclaimer = "Please don't activate any Word document by clicking onto them. This will interfere with the report generation. "
On Error Resume Next
Application.ScreenUpdating = False
Sheets("3d rotate").Visible = True
Var2 = 1
Set Wordobj = GetObject(, "Word.Application")
If err <> 0 Then
Set Wordobj = CreateObject("Word.Application")
err.Clear
End If
With Wordobj
.Documents.Add DocumentType:=wdNewBlankDocument
.ActiveDocument.ShowSpellingErrors = False
.ActiveDocument.LineNumbering.Active = False
.ActiveDocument.PageSetup.Orientation = wdOrientLandscape 'wdOrientPortrait
'.ActiveDocument.PageSetup.Orientation = wdOrientPortrait 'wdOrientPortrait
.ActiveWindow.ActivePane.View.Zoom.Percentage = 25
.Application.StatusBar = disclaimer
End With
i = 1
found_MS_Wurg = False
Do Until i > 50
dummy = "Document" & i
If dummy = Wordobj.ActiveDocument.name Then
Wordobj.Windows(i).Activate
Wordobj.Visible = True
Application.StatusBar = disclaimer & "Transfering information into MS Word"
found_MS_Wurg = True
i = 51
End If
i = i + 1
Loop
With Wordobj.ActiveWindow
With .View
.ShowAnimation = True
.Draft = False
.WrapToWindow = False
.ShowPicturePlaceHolders = False
.ShowFieldCodes = False
.ShowBookmarks = False
.FieldShading = wdFieldShadingWhenSelected
.ShowTabs = False
.ShowSpaces = False
.ShowParagraphs = False
.ShowHyphens = False
.ShowHiddenText = False
.ShowAll = False
.ShowDrawings = True
.ShowObjectAnchors = False
.ShowTextBoundaries = False
.ShowHighlight = True
.ShowOptionalBreaks = False
.DisplayPageBoundaries = True
.DisplaySmartTags = True
End With
End With
If found_MS_Wurg = False Then
msg = MsgBox("Error while trying to open MS Word")
End If
End If 'word_out
'***************************************
'***************************************
'***************************************
'Read important parameters
Replicate = Sheets("3d rotate").Cells(16, 20)
three_d_plot = Sheets("3d rotate").Cells(168, 22)
rfu_plot = Sheets("3d rotate").Cells(170, 22)
pie_chart = Sheets("3d rotate").Cells(172, 22)
array_graph = Sheets("3d rotate").Cells(174, 22)
Number_hits_pointer(1) = 996
Number_hits_pointer(2) = 994
Number_hits_pointer(3) = 993
number_of_hits = 0
For i = 1 To 3
histogram(i) = Sheets("3d rotate").Cells(154 + i * 2, 22)
kinasegroup(i) = Sheets("3d rotate").Cells(160 + i * 2, 22)
upperlimits(i) = Sheets("3d rotate").Cells(148 + i * 2, 22)
kinaselist(i) = Sheets("3d rotate").Cells(174 + i * 2, 22)
If upperlimits(i) = 341 Then
If histogram(i) Then
number_of_hits = number_of_hits + Sheets("3d rotate").Cells(Number_hits_pointer(i), 1)
End If
Else
number_of_hits = number_of_hits + (Number_of_Drugs * max_hits / Replicate)
End If
Next
Y_distance = 15
max_hits = Sheets("3d rotate").Cells(32, 22)
Exclusion_Limit = Sheets("3d rotate").Cells(34, 22)
Number_of_Drugs = Sheets("3d rotate").Cells(16, 22)
'Graph_Options = Sheets("3d rotate").Cells(37, 22)
headline_font = Sheets("3d rotate").Cells(76, 23)
body_font = Sheets("3d rotate").Cells(77, 23)
Header_or_Footer = Sheets("3d rotate").Cells(101, 22)
date_YON = Sheets("3d rotate").Cells(130, 24)
'Variabeln mit denen die Bildgrosse in MS Word gesteuert wird
X_graph = Sheets("3d rotate").Cells(146, 23)
y_graph = Sheets("3d rotate").Cells(147, 23)
'***************************************
'***************************************
'***************************************
If number_of_hits > 3400 Then
msg = MsgBox("You are trying to create a report with " & number_of_hits & " graphs." & _
vbNewLine & "The number of graphs is limited to 3400 due to memory restriction." _
& vbNewLine & "Please reduce the number of graphs in Report Settings Form." _
& vbNewLine & vbNewLine & "This routine aborts now.")
Exit Sub
End If
'Losche alten Report
Application.Run "clear_detailed_results", "Detailed Results", body_font
If word_out Then
'Create a header for the experiment in MS Word
With Wordobj
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.TypeText text:="Procognia Kinome 2.0 Selectivity Assay " & Sheets("3d rotate").Cells(128, 22)
.NormalTemplate.AutoTextEntries("Confidential, Page #, Date").Insert Where _
:=Selection.Range, RichText:=True
.NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=Selection. _
Range, RichText:=True
.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
.Application.StatusBar = disclaimer & " Transfering data."
End With
End If 'word out
Application.Run "results_header", date_YON, body_font
j = j + 10
Sheets("3d rotate").Cells(80, 22) = j
If word_out Then
Sheets("detailed results").Cells(5, 2).Resize(8, 1).Select
Application.Run "word_output", Wordobj, disclaimer, 1
End If 'word out
For i = 1 To Number_of_Drugs
neue_seite = False
cmpd_name = Sheets("3d rotate").Cells(8999 + i, 1)
Start = 4 + j + i
Application.Run "Table_text", i, j, Start, headline_font
Sheets("detailed results").Select
Sheets("detailed results").Cells(i + j + 4, 2).Resize(5, 14).Select
'Application.Run "wrap_my_txt", True, body_font
Sheets("detailed results").Select
If word_out Then
Sheets("detailed results").Cells(i + j + 4, 2).Resize(5, 14).Select
Application.Run "word_output", Wordobj, disclaimer, 1
End If
j = j + 4
weiter = True
Show_Graph = True
Sheets("3d rotate").Cells(84, 22) = "true"
'**********************
'determine how many hits are present in one set of results
'**********************
If Sheets("3d rotate").Cells(996, 1 + i) > (Exclusion_Limit - 1) Then
Sheets("detailed results").Cells(5 + i + j, 2) = "Number of Hits above the limit " & Exclusion_Limit
j = j + 3
weiter = False
Show_Graph = False
End If
If Sheets("3d rotate").Cells(84, 22) = False Then
Show_Graph = False
End If
If Show_Graph Then
Application.StatusBar = "Populate graphs with data: " & i
Application.ScreenUpdating = False
Application.Run "copy_graph_data", i
graphcount = 0
If array_graph Then
NoG = NoG + 1
neue_seite = True
Application.Run "array_graph", NoG, i, j, headline_font, Wordobj, word_out, disclaimer
End If
If three_d_plot Then
NoG = NoG + 1
neue_seite = True
graphcount = graphcount + 1
' msg = MsgBox("i j " & i & " " & j)
Application.Run "plot_DDD_graph", NoG, i, j
Sheets("detailed results").Select
Sheets("detailed results").Cells(5 + i + j, 2).Select
j = j + Y_distance
If word_out Then
Application.Run "word_output", Wordobj, disclaimer, 2
End If 'word out
End If 'three d plot
'Application.ScreenUpdating = True
' msg = MsgBox("ddd plot")
If rfu_plot Then
NoG = NoG + 1
neue_seite = True
graphcount = graphcount + 1
' msg = MsgBox("i j " & i & " " & j)
Application.Run "rfu_plot", NoG, i, j
Sheets("detailed results").Select
Sheets("detailed results").Cells(5 + i + j, 2).Select
j = j + Y_distance
If word_out Then
Application.Run "word_output", Wordobj, disclaimer, 2
End If 'word out
End If 'rfu plot
If pie_chart Then
NoG = NoG + 1
neue_seite = True
graphcount = graphcount + 1
Application.Run "pie_chart", NoG, i, j
Sheets("detailed results").Select
Sheets("detailed results").Cells(5 + i + j, 2).Select
j = j + Y_distance
If word_out Then
Application.Run "word_output", Wordobj, disclaimer, 2
End If 'word out
End If 'pie chart
If word_out Then
If neue_seite Then
Application.Run "word_output", Wordobj, disclaimer, 3
End If ' neue seite
End If 'word out
'Feststellen um wieviel Zeilenvorschub gebtaucht wird um fur das Arrayimage zu kompensierren
If graphcount = 1 Then
j = j + 12
End If
'Hier den text ausgeben
For teiltabelle = 1 To 3
Application.Run "kinase_bodytext", teiltabelle, i, j, upperlimits(teiltabelle), Start, NoG, Replicate, Y_distance, X_graph, y_graph, Wordobj, disclaimer, body_font, word_out, kinasegroup(teiltabelle), histogram(teiltabelle)
If kinasegroup(teiltabelle) Then
j = Sheets("3d rotate").Cells(80, 22)
NoG = Sheets("3d rotate").Cells(82, 22)
If kinaselist(teiltabelle) Then
Application.Run "kinaselist", teiltabelle, j, i, Wordobj, disclaimer, cmpd_name, word_out
j = Sheets("3d rotate").Cells(80, 22)
End If
End If
Next
End If 'show graph
j = j + 5
Next
Sheets("3d rotate").Visible = xlVeryHidden
Application.ScreenUpdating = True
If word_out Then
Wordobj.Visible = True
End If
Application.StatusBar = ""
End Sub
MS Word also becomes pretty slow when pumping in so many data. Is that a limitation of MS Word or do I have a programming error in my code?
Has anybody of you written a script that outputs a couple of 1000 jpg picture in MS Word?
Code
Sub open_Word()
Dim Exclusion_Limit, Y_distance, NoG, oldj, Number_of_Drugs, max_hits, i, Replicate, j, ii, msg As Integer
Dim Start, graphcount, number_of_hits, teiltabelle, Number_hits_pointer(3), upperlimits(3) As Integer
Dim Zeilen, Var, Var2, X_graph, y_graph, Header_or_Footer, List_y_pos(4) As Integer
Dim found_MS_Wurg, weiter, Show_Graph, date_YON As Boolean
Dim dummy, body_font, headline_font, cmpd_name, disclaimer, error_string As String
Dim Wordobj As Word.Application
Dim WordDoc As Word.Document
Dim kinaselist(4), kinasegroup(3), histogram(3), neue_seite, three_d_plot, rfu_plot, pie_chart, array_graph, word_out As Boolean
word_out = Sheets("3d rotate").Cells(73, 23)
'Teste wieviele graphiken vorhanden sind.
If word_out Then
disclaimer = "Please don't activate any Word document by clicking onto them. This will interfere with the report generation. "
On Error Resume Next
Application.ScreenUpdating = False
Sheets("3d rotate").Visible = True
Var2 = 1
Set Wordobj = GetObject(, "Word.Application")
If err <> 0 Then
Set Wordobj = CreateObject("Word.Application")
err.Clear
End If
With Wordobj
.Documents.Add DocumentType:=wdNewBlankDocument
.ActiveDocument.ShowSpellingErrors = False
.ActiveDocument.LineNumbering.Active = False
.ActiveDocument.PageSetup.Orientation = wdOrientLandscape 'wdOrientPortrait
'.ActiveDocument.PageSetup.Orientation = wdOrientPortrait 'wdOrientPortrait
.ActiveWindow.ActivePane.View.Zoom.Percentage = 25
.Application.StatusBar = disclaimer
End With
i = 1
found_MS_Wurg = False
Do Until i > 50
dummy = "Document" & i
If dummy = Wordobj.ActiveDocument.name Then
Wordobj.Windows(i).Activate
Wordobj.Visible = True
Application.StatusBar = disclaimer & "Transfering information into MS Word"
found_MS_Wurg = True
i = 51
End If
i = i + 1
Loop
With Wordobj.ActiveWindow
With .View
.ShowAnimation = True
.Draft = False
.WrapToWindow = False
.ShowPicturePlaceHolders = False
.ShowFieldCodes = False
.ShowBookmarks = False
.FieldShading = wdFieldShadingWhenSelected
.ShowTabs = False
.ShowSpaces = False
.ShowParagraphs = False
.ShowHyphens = False
.ShowHiddenText = False
.ShowAll = False
.ShowDrawings = True
.ShowObjectAnchors = False
.ShowTextBoundaries = False
.ShowHighlight = True
.ShowOptionalBreaks = False
.DisplayPageBoundaries = True
.DisplaySmartTags = True
End With
End With
If found_MS_Wurg = False Then
msg = MsgBox("Error while trying to open MS Word")
End If
End If 'word_out
'***************************************
'***************************************
'***************************************
'Read important parameters
Replicate = Sheets("3d rotate").Cells(16, 20)
three_d_plot = Sheets("3d rotate").Cells(168, 22)
rfu_plot = Sheets("3d rotate").Cells(170, 22)
pie_chart = Sheets("3d rotate").Cells(172, 22)
array_graph = Sheets("3d rotate").Cells(174, 22)
Number_hits_pointer(1) = 996
Number_hits_pointer(2) = 994
Number_hits_pointer(3) = 993
number_of_hits = 0
For i = 1 To 3
histogram(i) = Sheets("3d rotate").Cells(154 + i * 2, 22)
kinasegroup(i) = Sheets("3d rotate").Cells(160 + i * 2, 22)
upperlimits(i) = Sheets("3d rotate").Cells(148 + i * 2, 22)
kinaselist(i) = Sheets("3d rotate").Cells(174 + i * 2, 22)
If upperlimits(i) = 341 Then
If histogram(i) Then
number_of_hits = number_of_hits + Sheets("3d rotate").Cells(Number_hits_pointer(i), 1)
End If
Else
number_of_hits = number_of_hits + (Number_of_Drugs * max_hits / Replicate)
End If
Next
Y_distance = 15
max_hits = Sheets("3d rotate").Cells(32, 22)
Exclusion_Limit = Sheets("3d rotate").Cells(34, 22)
Number_of_Drugs = Sheets("3d rotate").Cells(16, 22)
'Graph_Options = Sheets("3d rotate").Cells(37, 22)
headline_font = Sheets("3d rotate").Cells(76, 23)
body_font = Sheets("3d rotate").Cells(77, 23)
Header_or_Footer = Sheets("3d rotate").Cells(101, 22)
date_YON = Sheets("3d rotate").Cells(130, 24)
'Variabeln mit denen die Bildgrosse in MS Word gesteuert wird
X_graph = Sheets("3d rotate").Cells(146, 23)
y_graph = Sheets("3d rotate").Cells(147, 23)
'***************************************
'***************************************
'***************************************
If number_of_hits > 3400 Then
msg = MsgBox("You are trying to create a report with " & number_of_hits & " graphs." & _
vbNewLine & "The number of graphs is limited to 3400 due to memory restriction." _
& vbNewLine & "Please reduce the number of graphs in Report Settings Form." _
& vbNewLine & vbNewLine & "This routine aborts now.")
Exit Sub
End If
'Losche alten Report
Application.Run "clear_detailed_results", "Detailed Results", body_font
If word_out Then
'Create a header for the experiment in MS Word
With Wordobj
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.TypeText text:="Procognia Kinome 2.0 Selectivity Assay " & Sheets("3d rotate").Cells(128, 22)
.NormalTemplate.AutoTextEntries("Confidential, Page #, Date").Insert Where _
:=Selection.Range, RichText:=True
.NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=Selection. _
Range, RichText:=True
.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
.Application.StatusBar = disclaimer & " Transfering data."
End With
End If 'word out
Application.Run "results_header", date_YON, body_font
j = j + 10
Sheets("3d rotate").Cells(80, 22) = j
If word_out Then
Sheets("detailed results").Cells(5, 2).Resize(8, 1).Select
Application.Run "word_output", Wordobj, disclaimer, 1
End If 'word out
For i = 1 To Number_of_Drugs
neue_seite = False
cmpd_name = Sheets("3d rotate").Cells(8999 + i, 1)
Start = 4 + j + i
Application.Run "Table_text", i, j, Start, headline_font
Sheets("detailed results").Select
Sheets("detailed results").Cells(i + j + 4, 2).Resize(5, 14).Select
'Application.Run "wrap_my_txt", True, body_font
Sheets("detailed results").Select
If word_out Then
Sheets("detailed results").Cells(i + j + 4, 2).Resize(5, 14).Select
Application.Run "word_output", Wordobj, disclaimer, 1
End If
j = j + 4
weiter = True
Show_Graph = True
Sheets("3d rotate").Cells(84, 22) = "true"
'**********************
'determine how many hits are present in one set of results
'**********************
If Sheets("3d rotate").Cells(996, 1 + i) > (Exclusion_Limit - 1) Then
Sheets("detailed results").Cells(5 + i + j, 2) = "Number of Hits above the limit " & Exclusion_Limit
j = j + 3
weiter = False
Show_Graph = False
End If
If Sheets("3d rotate").Cells(84, 22) = False Then
Show_Graph = False
End If
If Show_Graph Then
Application.StatusBar = "Populate graphs with data: " & i
Application.ScreenUpdating = False
Application.Run "copy_graph_data", i
graphcount = 0
If array_graph Then
NoG = NoG + 1
neue_seite = True
Application.Run "array_graph", NoG, i, j, headline_font, Wordobj, word_out, disclaimer
End If
If three_d_plot Then
NoG = NoG + 1
neue_seite = True
graphcount = graphcount + 1
' msg = MsgBox("i j " & i & " " & j)
Application.Run "plot_DDD_graph", NoG, i, j
Sheets("detailed results").Select
Sheets("detailed results").Cells(5 + i + j, 2).Select
j = j + Y_distance
If word_out Then
Application.Run "word_output", Wordobj, disclaimer, 2
End If 'word out
End If 'three d plot
'Application.ScreenUpdating = True
' msg = MsgBox("ddd plot")
If rfu_plot Then
NoG = NoG + 1
neue_seite = True
graphcount = graphcount + 1
' msg = MsgBox("i j " & i & " " & j)
Application.Run "rfu_plot", NoG, i, j
Sheets("detailed results").Select
Sheets("detailed results").Cells(5 + i + j, 2).Select
j = j + Y_distance
If word_out Then
Application.Run "word_output", Wordobj, disclaimer, 2
End If 'word out
End If 'rfu plot
If pie_chart Then
NoG = NoG + 1
neue_seite = True
graphcount = graphcount + 1
Application.Run "pie_chart", NoG, i, j
Sheets("detailed results").Select
Sheets("detailed results").Cells(5 + i + j, 2).Select
j = j + Y_distance
If word_out Then
Application.Run "word_output", Wordobj, disclaimer, 2
End If 'word out
End If 'pie chart
If word_out Then
If neue_seite Then
Application.Run "word_output", Wordobj, disclaimer, 3
End If ' neue seite
End If 'word out
'Feststellen um wieviel Zeilenvorschub gebtaucht wird um fur das Arrayimage zu kompensierren
If graphcount = 1 Then
j = j + 12
End If
'Hier den text ausgeben
For teiltabelle = 1 To 3
Application.Run "kinase_bodytext", teiltabelle, i, j, upperlimits(teiltabelle), Start, NoG, Replicate, Y_distance, X_graph, y_graph, Wordobj, disclaimer, body_font, word_out, kinasegroup(teiltabelle), histogram(teiltabelle)
If kinasegroup(teiltabelle) Then
j = Sheets("3d rotate").Cells(80, 22)
NoG = Sheets("3d rotate").Cells(82, 22)
If kinaselist(teiltabelle) Then
Application.Run "kinaselist", teiltabelle, j, i, Wordobj, disclaimer, cmpd_name, word_out
j = Sheets("3d rotate").Cells(80, 22)
End If
End If
Next
End If 'show graph
j = j + 5
Next
Sheets("3d rotate").Visible = xlVeryHidden
Application.ScreenUpdating = True
If word_out Then
Wordobj.Visible = True
End If
Application.StatusBar = ""
End Sub